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

162
Vistas
I want to reload my page x seconds after a button is clicked

So i want my page to reload an amount of seconds after the button is clicked. Right now it reloads every 5 seconds automatically. But if i put the timeout function in the addEvenlistener then it errors. What can i do to solve it?

button.addEventListener(
  'click',
  () =>
    (cover.style.visibility = 'hidden') && (button.style.visibility = 'hidden'),
);

setTimeout(function () {
  window.location.reload();
}, 5000);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Weird, this should work. Are you sure you didn't forget the curly braces in the click callback?

button.addEventListener('click', () => {
  cover.style.visibility = 'hidden';
  button.style.visibility = 'hidden';
  setTimeout(function () {
    window.location.reload();
  }, 5000);
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

You just need to write it inside the EventListener as @Jonas mentioned. And also you can have that timeout value to be dynamic as well

var timeoutValue = 5000
button.addEventListener('click', () => {
  cover.style.visibility = 'hidden';
  button.style.visibility = 'hidden';
  setTimeout(function () {
    window.location.reload();
  }, timeoutValue);
});

about 4 years ago · Juan Pablo Isaza 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