Home >Web Front-end >JS Tutorial >Is it possible to remove an anonymous event listener without replacing the element?
When an element has an anonymous event listener added to it, such as:
element.addEventListener(event, function(){/* do work here */}, false);
You can remove this event listener without replacing the element?
There is no easy way to remove an event handler unless you have stored a reference to the event handler at creation. Typically, you add these elements to the main object on that page to iterate over them and discard them when you are done working with that object.
The above is the detailed content of Is it possible to remove an anonymous event listener without replacing the element?. For more information, please follow other related articles on the PHP Chinese website!