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

203
Views
cambiar el evento en EventListener no se activa

Así que hice una pequeña versión de mi problema. Aquí estoy agregando texto en un elemento de entrada. Pero cuando se agrega, no activa el detector de eventos.

 function testFunction() { document.getElementById("testInput").addEventListener("change", () => { console.log("hi"); }); } function testText() { document.getElementById("testInput").value = "Hello there"; } testFunction();
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" href="styles.css" /> <title>Document</title> </head> <body> <script></script> <button onclick="testText()" style="height: 20px"></button> <input id="testInput" /> <script src="script.js"></script> </body> </html>

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

0

Debe crear el evento manualmente y usar el método dispatchEvent() para activar el evento en el elemento de destino.

 function testFunction() { document.getElementById("testInput").addEventListener("input", () => { console.log("hi"); }); } function testText() { document.getElementById("testInput").value = "Hello there"; let event = new Event("input"); document.getElementById("testInput").dispatchEvent(event); } testFunction();
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" href="styles.css" /> <title>Document</title> </head> <body> <script></script> <button onclick="testText()" style="height: 20px"></button> <input id="testInput" /> <script src="script.js"></script> </body> </html>

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!