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

233
Views
cómo crear <input onchange='myFunction()' /> dinámicamente con función

Sé que puedes usar document.createElement para esto, pero obtengo una excepción al hacer esto:

 document.createElement("<input onchange='myFunction()' />");

Error:

 Uncaught DOMException: Failed to execute 'createElement' on 'Document': The tag name provided ('<input onchange='myFunction()' />') is not a valid name.

¿Sabes cómo crear un elemento dinámicamente con una función?

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

0

Debes hacerlo en 3 tiempos:

  • Primero creando el elemento
  • Luego sumando la función
  • Finalmente agregándolo al dom

 const myFunction = () => { console.log("hello world") } const btn = document.createElement('button') btn.innerText = "MyBtn" btn.addEventListener('click', myFunction) document.body.appendChild(btn)

about 4 years ago · Juan Pablo Isaza Report

0

Lo siento, fui demasiado rápido para pedir ayuda. Pero esta es la respuesta:

 newInput3.onchange = myFunction;

myFunction no debe ser una cadena real.

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!