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

124
Vistas
How to remove the event listeners of all buttons when only one is clicked

I'm doing a quiz app, and when the user picks an answer, I want to display the next question. The thing is, the event listener on the other buttons are not removed, only the button the user clicked (using once:true). Is there a way that I can remove all event listeners on the other buttons when only one of them is fired?

Here is my code:

   function enableButtons(correctAnswer) {
    
    btns.forEach((btn) => {
        btn.addEventListener(
            'click',
            function () {
                if (checkAnswer(btn.textContent, correctAnswer)) {
                    btn.classList.add('correctAnswer');
                } else {
                    btn.classList.add('wrongAnswer');
                }

                setTimeout(function () {
                    removeBtnClasses(btn),
                    nextQuestion()
                }, 2000);
            },
            {once: true}
        )
    })

}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can write removeEventListener method.

A guide for removeEventListener : https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener

And I am not sure about second method but I think you can add disabled attribute to the button, I haven't worked with DOM for long time so I don't remember if second method would work.

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