Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda