jQuery Undelegate Event

Thursday, July 5, 2012

The jQuery event undelegate() method removes one or more event handlers for specified elements that are children of selected elements, and specifies a function to run when the events occur. In addition, event handlers that are removed using the jQuery undelegate() method will work for both current and future elements. As of jQuery 1.7, the undelegate() method has been superseded by the .off() method. For earlier versions, it remains the most effective means to use event delegation.



selectorOptional selector to remove event handlers from
eventOptional events to remove.
functionOptional function to remove


In the following jQuery example, the undelegate() method removes the click event from the div element. When the "imgUndelegate" element is clicked, the slideToggle effect is removed from click event attached to the "imgMouse" element. In this example, the div element will be shown or hidden as the mouse icon is clicked. Clicking the Undelegate image removes this event. Try it yourself, by clicking the mouse icon first, then the Undelegate image.

<div id="divParent">
    <img id="imgMouse"src="#" />
    <img id="imgUnbind"src="#" />
    <div id="divChild">
    <div id="divText">Click the mouse icon to toggle ....

$("#divParent").delegate("img", "click", function () {
$("#imgUndelegate").click(function () {

mouse close
Click the mouse icon to toggle this display, or click the X to undelegate the events!

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

HTML CSS and JavaScript Editor JavaScript and jQuery: The Missing Manual Pro jQuery