.die()
Contents:
- die()
- .die()
- die( eventType [ , handler ] )
- .die( eventType [, handler] )
- .die( eventTypes )
.die() Returns: jQuery
Description: Remove all event handlers previously attached using .live() from the elements.
-
version added: 1.4.1.die()
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.
As of jQuery 1.7, use of .die()
(and its complementary method, .live()
) is not recommended. Instead, use .off()
to remove event handlers bound with .on()
Note: In order for .die() to function correctly, the selector used with it must match exactly the selector initially used with .live().
.die( eventType [, handler] ) Returns: jQuery
Description: Remove an event handler previously attached using .live() from the elements.
-
version added: 1.3.die( eventType [, handler] )
eventTypeA string containing a JavaScript event type, such as
click
orkeydown
.handlerThe function that is no longer to be executed.
-
version added: 1.4.3.die( eventTypes )
eventTypesA map of one or more event types, such as
click
orkeydown
and their corresponding functions that are no longer to be 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.
Note: In order for .die()
to function correctly, the selector used with it must match exactly the selector initially used with .live()
.
Examples:
Example: Can bind and unbind events to the colored button.
<!DOCTYPE html>
<html>
<head>
<style>
button { margin:5px; }
button#theone { color:red; background:yellow; }
</style>
<script src="http://code.jquery.com/jquery-1.7rc2.js"></script>
</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>
<script>
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>
</body>
</html>
Example: To unbind all live events from all paragraphs, write:
$("p").die()
Example: To unbind all live click events from all paragraphs, write:
$("p").die( "click" )
Example: 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.