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

111
Views
¿Cómo puedo agregar onclick o eventListener mientras agrego un botón usando javascript?

bueno, estoy tratando de agregar un botón cuando el usuario hace clic en un botón de agregar, también el botón que se agrega debe tener un atributo onclick o eventListener() para llamar a deleteMyOrder() entonces, ¿cómo puedo lograr esto? He hecho lo siguiente pero sigue sin funcionar:

 <body> <div id="insertHere"> </div> <input type="button" value="addButton" onclick="myFunc()" /> <script> function myFunc() { var cell4 = document.getElementById('insertHere'); var element3 = document.createElement("input"); element3.type = "button"; element3.name = "add"; element3.id = "forRemove"; element3.value="Remove"; element3.className="btn btn-outline-danger btn-sm"; element3.onclick = "deleteMyOrder()"; cell4.appendChild(element3); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede agregar un detector de eventos en el botón creado dinámicamente como este

 element3.addEventListener('click', () => { console.log('button clicked') }) 

 <body> <div id="insertHere"> </div> <input type="button" value="addButton" onclick="myFunc()" /> <script> function myFunc() { var cell4 = document.getElementById('insertHere'); var element3 = document.createElement("input"); element3.type = "button"; element3.name = "add"; element3.id = "forRemove"; element3.value="Remove"; element3.className="btn btn-outline-danger btn-sm"; element3.addEventListener('click', () => { console.log('button clicked'); // your click action here }) cell4.appendChild(element3); } </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!