cgprew
Last Updated: February 25, 2016
·
341
· bhousman
9b51c0db928eefd139d71297e5893a2e

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);
Say Thanks
Respond