Description: Remove all event handlers previously attached using .live() from the elements.
.die()
version added: 1.4.1
Any handler that has been attached with .live() can be removed with .die(). This method is analogous to calling .unbind() with no arguments, which is used to remove all handlers attached with .bind().
See the discussions of .live() and .unbind() for further details.
Description: Remove an event handler previously attached using .live() from the elements.
.die( eventType, [ handler ] )
version added: 1.3
eventType
A string containing a JavaScript event type, such as "click" or "keydown."
handler
The function that is to be no longer executed.
Any handler that has been attached with .live() can be removed with .die(). This method is analogous to .unbind(), which is used to remove handlers attached with .bind().
See the discussions of .live() and .unbind() for further details.
Examples
Example 1
Can bind and unbind events to the colored button.Example 1 - Full source:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
function aClick() {
$("div").show().fadeOut("slow");
}
$("#bind").click(function () {
$("#theone").live("click", aClick)
.text("Can Click!");
});
$("#unbind").click(function () {
$("#theone").die("click", aClick)
.text("Does nothing...");
});
});
</script>
<style>
button { margin:5px; }
button#theone { color:red; background:yellow; }
</style>
</head>
<body>
<button id="theone">Does nothing...</button>
<button id="bind">Bind Click</button>
<button id="unbind">Unbind Click</button>
<div style="display:none;">Click!</div>
</body>
</html>
Example 2
To unbind all live events from all paragraphs, write:$("p").die()
Example 3
To unbind all live click events from all paragraphs, write:$("p").die( "click" )
Example 4
To unbind just one previously bound handler, pass the function in as the second argument:var foo = function () {
// code to handle some kind of event
};
$("p").live("click", foo);
// ... now foo will be called when paragraphs are clicked ...
$("p").die("click", foo);
// ... foo will no longer be called.
Was this information helpful?

