Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
A button do thing on clicking & undo it on another click

Hello,

I want to achieve the following:

When Button is clicked CSS Style changes to display: block on second click must be changed to display: none. And it must be looped

How to achieve that?

I managed to create this code which adds css style when clicked(but I can't make second click event):

const button = document.querySelector('button'); button.addEventListener('click', () => { const element = document.querySelector('div.wpcs_price_info ul'); element.setAttribute('style', 'display:block !important'); });

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Pretty easy, just add a if condition.

const button = document.querySelector("button");
let shown = false;
button.addEventListener("click", () => {
    const element = document.querySelector("div.wpcs_price_info ul");
    if (shown) {
        element.setAttribute("style", "display:none !important");
        shown = false;
    } else {
        element.setAttribute("style", "display:block !important");
        shown = true;
    }
});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!