Removing Event Handlers in JavaScript

var obj = document.getElementById("div1"); obj.addEventListener('click', clickHandler); . . . obj.removeEventListener('click', clickHandler);

You can also remove event handlers from the event using the removeEventListener() function on the DOM object. You need to specify the event type and the name of the event handler to remove. For example, the following code adds an event handler and then removes it:

function clickHandler(e){    . . . } var obj = document.getElementById("div1"); obj.addEventListener('click', clickHandler);

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.