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

171
Views
Un botón hace algo al hacer clic y lo deshace con otro clic

Hola,

Quiero lograr lo siguiente:

Cuando se hace clic en el botón, el estilo CSS cambia para mostrar: el bloque en el segundo clic debe cambiarse para mostrar: ninguno. Y debe estar en bucle

¿Cómo lograr eso?

Logré crear este código que agrega estilo css cuando se hace clic (pero no puedo hacer un segundo evento de clic):

 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

Bastante fácil, solo agregue una condición if.

 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!