O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required