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

154
Views
Crear botones HTML a partir de una matriz de nombres e insertarlos en el DOM

No puedo entender cómo convertirlos en botones usando la matriz:

 var widgetButtons = ["Zoom In", "Zoom Out", "Pan", "Search"]

Cualquier ayuda sería apreciada. Este es mi código que estoy tratando de usar

 <body> <div id="demo"></div> <script> var widgetButtons = ["Zoom In", "Zoom Out", "Pan", "Search"]; </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

En su HTML: <div id="new">

En tu JS/script:

 var widgetButtons = ["Zoom In", "Zoom Out", "Pan", "Search"]; var element = document.getElementById("new"); for (const widgetButtonsKey of widgetButtons) { var x = document.createElement("BUTTON"); x.innerText = widgetButtonsKey console.log(x); element.appendChild(x); }
about 4 years ago · Juan Pablo Isaza Report

0

Aquí hay otra forma de hacerlo, usando forEach() .

Los ID no pueden contener espacios, por lo que eliminamos el espacio del nombre/texto del elemento antes de configurar el ID.

 const widgetButtons = ["Zoom In", "Zoom Out", "Pan", "Search"] const demo = document.getElementById('demo'); widgetButtons.forEach( (item, idx) => { const btn = document.createElement('button'); btn.id = item.replace(' ', ''); btn.innerText = item; demo.appendChild(btn); });
 <html> <body> <div id="demo"></div> </body> </html>

about 4 years ago · Juan Pablo Isaza Report

0

Aquí hay otro enfoque.

 var widgetButtons = ["Zoom In", "Zoom Out", "Pan", "Search"]; document.getElementById('demo').innerHTML = widgetButtons.map(text=>{ return `<button>${text}</button>`; }).join(' ');
 <div id=demo></div>

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!