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

215
Views
ID de botón dinámico de Javascript

Hice dinámicamente un botón usando Javascript, ahora necesito darle una ID a ese botón, lo intenté con

 buttonElementBlokkeer.setAttribute("id", "buttonBlokkeer"); & buttonElementBlokkeer.id = "buttonBlokkeer"

Ambos no están funcionando. Los botones están anidados en una sección que ya tiene una identificación, ¿podría ser esta una razón por la que no funciona?

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

0

HTML

 <div id="divId"></div>

JS

 for (i = 1; i <= 3; i++) { var btn = document.createElement("BUTTON");// create button using java script btn.className = "btnsize"; btn.id = "btnid"+ i; var txt = document.createTextNode("Buttons"+i);//creat text on button btn.appendChild(txt);//attached text on button document.getElementById("divId").appendChild(btn);//atache button with text in div }
about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto:

 let button = document.createElement('input'); button.setAttribute('type', 'BUTTON'); button.setAttribute('ID', 'buttonBlokkeer'); button.setAttribute('value', 'BUTTON'); button.setAttribute('onclick', 'test()'); document.body.appendChild(button); function test() { console.log("BUTTON !"); alert("BUTTON !"); }

https://jsfiddle.net/onw2esyg/

about 4 years ago · Juan Pablo Isaza Report

0

Esto es trabajo para mí. Puede usar la función getElementsByClassName() si desea acceder por nombre de clase.

 <button id="changeId">Button1</button> <button onclick="update()">Update</button> <script> function update() { document.getElementById("changeId").id = "IdUpdated"; } </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!