Removing Event Listeners
It's good practice, especially in long-running web applications, to remove event listeners, such as the following:
element.removeEventListener(<event-name>, <callback>, <use-capture>);
You will need a reference to a callback function that was originally bound.
var element = document.getElementById('element');
function callback() {
console.log('You will see my 1x time.');
element.removeEventListener('click', callback);
}
// Add listener
element.addEventListener('click', callback);Written by Brian
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#