cgprew
Last Updated: February 25, 2016
·
361
· bhousman

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);