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

304
Views
Cambiar el tamaño de Iframe al hacer clic en el detector de eventos no funciona

Estoy tratando de cambiar el tamaño del iframe haciendo clic en el botón usando el detector de eventos de clic. Pero el iframe automáticamente ejecuta la función y ni siquiera he hecho clic en el botón...

Alguien dijo que esto es un duplicado de ¿Cómo pasar argumentos a la función de escucha addEventListener? pero no veo donde esta relacionado esto???

 const btn = document.querySelector('button'); const iframe = document.querySelector('iframe'); function change(w) { iframe.style.width = `${w}px`; } btn.addEventListener('click', change(150));
 iframe { width: 300px; height: 300px; background-color: blue; }
 <button>Change</button> <iframe src=""></iframe>

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

cambie su función de escucha de eventos así

 btn.addEventListener('click', () => change(150));

O

 btn.addEventListener('click', function() { change(150) });

addEventListener espera una definición de función y no una llamada de función como segundo argumento.

Para obtener más información, lea: https://www.w3schools.com/js/js_htmldom_eventlistener.asp

about 4 years ago · Santiago Trujillo 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!