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

78
Views
Haga clic en el botón y mostrar Alerta

El siguiente código muestra un cuadro de alerta:

Quiero que cada cuadro se muestre haciendo clic en su propio botón html

 <button class="btn-alert btn-success" type="submit">delete</button> <button class="btn-alert btn-success" type="submit">delete</button> <button class="btn-alert btn-success" type="submit">delete</button> <div class="alert-s col-4"></div> <div class="alert-s col-4"></div> <div class="alert-s col-4"></div>
 <script> const targetDiv = document.getElementById("alert"); const btn = document.getElementById("toggle"); function clickfn() { for(let i = 0; i < targetDiv.length; i++) { if (targetDiv.style.display = "none") { targetDiv.style.display = "block"; } else { targetDiv.style.display = "none"; } } }; </script>

¿alguien puede ayudarme a hacerlo?

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

0

Puede agregar una clase a todos sus botones, digamos toggle , luego use javascript para llamar a su function como:

 var btns = document.getElementsByClassName('toggles'); for (var i = 0; i < btns.length; i++) { btns[i].onclick = function () { alert("Finaly!"); } }
about 4 years ago · Juan Pablo Isaza Report

0

no necesita el bucle for ya que getElementById devuelve un solo elemento. Si desea mostrar una alerta en ambos botones, haga clic y no desea escribir dos códigos separados, asígneles un nombre de clase similar y consúltelos de esa manera usando document.querySelectorAll ( un nombre de clase de punto entre comillas ) .

 <button class="btn">Button one</button> <button class="btn">Button two</button> <script> const btns = document.querySelectorAll(".btn"); for (let i = 0; i < btns.length; i++) { btns[i].onclick = () => { alert(`button ${i + 1} was clicked`); }; } </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!