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

210
Vistas
How to remove or disable evenListeners on click

I got to evenListeners one to start the timer and one to stop it Is it possible to make the start one to work only once and then get disabled until the stop button is clicked ???

startButton.addEventListener("click", startTimer);
stopButton.addEventListener("click", function stopFunction() {})
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Yes, you can just use removeEventListener

function startTimer() {
  // whatever code

  // Disable after use
  startButton.removeEventListern("click", startTimer);
}
startButton.addEventListener("click", startTimer);

// Reset listener after stop button clicked
stopButton.addEventListener("click", () => {
  startButton.removeEventListener("click", startTimer);
  startButton.addEventListener("click", startTimer);
});

Can also simplify with shorthand:

const disableBtn = () => startButton.removeEventListener("click", startTimer);
const enableBtn = () => (disableBtn(), startButton.addEventListener("click", startTimer));

function startTimer() {
  // whatever code
  disableBtn();
}
enableBtn();
stopButton.addEventListner("click", enableBtn);
about 4 years ago · Juan Pablo Isaza Denunciar

0

by using the line below you can remove the listener.

 startbutton.removeEventListener("click", startTimer);

and if you want to handle it with another button just call a function on click.

function stopFunction() {
   startbutton.removeEventListener("click", startTimer);
});
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