0

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>
Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48

0 Answers0