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

412
Views
¿Múltiples botones 'ver más'?

Estoy buscando agregar varios botones 'ver más' en mi página. En el momento en que cuando agrego uno nuevo solo funciona el primer botón y se rompe el segundo. Entonces, el primer botón funciona bien, pero cuando intenté copiar esta miniatura y hacer otra con la misma, vi más detalles. El segundo botón solo cambia las primeras miniaturas 'ver más'

 function toggle() { let Text = document.getElementById('moreDetails'); if (Text.style.display == "none") { Text.style.display = "block"; } else { Text.style.display = "none"; } } document.getElementById("moreDetails").style.display = "none";
 <div id="thumbnail-frame"> <div id="thumbnail" <div id="details"> <div id="moreDetails"> <h3> 001 </h3> <h3> Saturate Radio </h3> <h4> N00DS </h4> </div> <button title="Click to Show" type="button" onclick="toggle()">More Details</button> </div> </div> <div id="thumbnail-frame"> <div id="thumbnail" <div id="details"> <div id="moreDetails"> <h3> 002 </h3> <h3> Saturate Radio </h3> <h4> N00DS </h4> </div> <button title="Click to Show" type="button" onclick="toggle()">More Details</button> </div> </div>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El problema principal es que no puede tener identificaciones duplicadas en una página. El uso de clases funciona bien, o el uso de la posición relativa de sus elementos html.

 function toggle(button){ // this works because the button is immediately after the "moreDetails" element it pertains to let Text = button.previousElementSibling; // this would work if you move the button so it is not immediately after moreDetails, but still in the same parent div. //let Text = button.parentElement.querySelector(".moreDetails"); if(Text.style.display == "none"){ Text.style.display= "block"; } else { Text.style.display = "none"; } } const moreDetailses = document.querySelectorAll(".moreDetails"); for (let i = 0; i < moreDetailses.length; i++) { moreDetailses[i].style.display = "none"; }
 <div class="details"> <div class="moreDetails"> <h3> 001 </h3> <h3> Saturate Radio </h3> <h4> N00DS </h4> </div> <button title="Click to Show" type="button" onclick="toggle(this)">More Details</button> </div> <div class="details"> <div class="moreDetails"> <h3> 002 </h3> <h3> Saturate Radio </h3> <h4> N00DS </h4> </div> <button title="Click to Show" type="button" onclick="toggle(this)">More Details</button> </div>

about 4 years ago · Juan Pablo Isaza Report

0

Solo se permite usar una identificación una vez por página, por lo que su script de alternancia no funcionará como se espera cuando tenga varios elementos con la misma identificación.

Para que sea funcional y mantener los cambios necesarios al mínimo, debe hacer lo siguiente:

  • cambie la identificación a la clase para que el HTML sea válido
  • permita que su botón de alternar pase por sí mismo, por ejemplo onclick="toggle(this)"
  • muévase a través del dom para llegar al elemento que desea alternar (parentNode, firstChild, etc.)
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!