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

154
Visualizações
Reset element click listener to default behavior JavaScript

Let's say i have a anchor tag which has a listener set by some library (that is using the class to add it, which is also used to add style, therefore I can't just remove the class from the element).

Let's also say that I don't want that listener anymore, and so I would like just to have the browser-default behavior, how do I reset it to default?

In this case we are talking of a anchor tag, but I would like to have a general solution to this.

Example:

// library example code
[...document.getElementsByClassName("test")].forEach(el =>{
  el.addEventListener("click", e => {
    e.preventDefault()
    alert("wrong listener")
  })
})

// how to reset?
// document.getElementsByClassName("test").forEach(el => el.resetListeners())
//                                                         ^^^^^^^^^^^^^^^^^
.test{
  color: red;
}
<a href="#" class="test">click me</a>

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