The jQuery event die() method removes one or more event handlers previously attached using .live() method from the elements. As of jQuery 1.7, the use of .die() and .live() is not recommended. The recommended approach
is to use .off() to remove event handlers bound with .on().
Syntax
$(selector).die(event,function)
Parameter | Description |
event | One or more events to attach. Event values are separated by space |
function | Optional function to run when the event(s) occur |
Basic Example
In the following jQuery example, the die() method removes the click event from the element with an id of "imgMouse". When the "imgDie" element is clicked, the "click" event is removed from "imgMouse".
In this example, the div element will be shown or hidden as the mouse icon is clicked. Clicking the Die image removes this event. Try it yourself, by clicking the mouse icon first, then the Die image. You
can copy, paste, and modify this code using our online HTML editor (found below in the resources section).
<div id="divParent">
<img id="imgMouse"src="#" />
<img id="imgDie"src="#" />
<div id="divChild">
<div id="divText">Click the mouse icon to toggle ....
</div>
</div>
$("#imgMouse").live("click", function () {
$("#divChild").slideToggle();
});
$("#imgDie").click(function () {
$("#imgMouse").die("click");
});
Click the mouse icon to toggle this display, or click the X to remove the event handler!
Did you find the page informational and useful? Share it using one of your favorite social sites.
Recommended Books & Training Resources