Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

298
Vistas
Changing Iframe size by click event listener not working

I'm trying to change the iframe size by clicking the button by using the click event listener. But the iframe auto runs the function and I haven't even clicked the button...

Someone said this is a duplicate of How to pass arguments to addEventListener listener function? but I don't see where is this even related???

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 Respuestas
Responde la pregunta

0

change your event listener function like so

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

OR

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

addEventListener expects a function definition and not a function call as second argument.

For more read: https://www.w3schools.com/js/js_htmldom_eventlistener.asp

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda