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

110
Views
botón onclick solo una identificación div está en acción de llamada

Creé un botón que ve los elementos que están ocultos al hacer clic, pero hay muchos div con la misma identificación, pero quiero ocultarlos todos, pero solo está ocultando uno que estoy usando debajo del código, pero solo está viendo u ocultando, el primer div solo se oculta al hacer clic descansa no se esconde

 <button onclick="myFunction()" class="btn-custom">View the Picture</button> <div id=hide></div> <div id=hide></div> <div id=hide></div> <div id=hide></div> <script> function myFunction() { var x = document.getElementById("hide"); if (x.style.display === "none") { x.style.display = "block"; } else { x.style.display = "none"; } } </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su HTML no es válido: los id deben ser únicos.

En su lugar, use una clase para identificar los elementos y querySelectorAll para seleccionarlos todos:

 <div class=hide>a</div> <div class=hide>b</div> <div class=hide>c</div> <div class=hide>d</div> <button onclick="myFunction()">Toggle</button> <script> function myFunction() { var x = document.querySelectorAll(".hide"); x.forEach(y => { if (y.style.display === "none") { y.style.display = "block"; } else { y.style.display = "none"; } }) } </script>

about 4 years ago · Juan Pablo Isaza 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!