forked from jquery/api.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdie.xml
83 lines (78 loc) · 3.54 KB
/
die.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?xml version="1.0"?>
<entry type="method" name="die" return="jQuery" deprecated="1.7">
<title>.die()</title>
<desc>Remove event handlers previously attached using <code>.live()</code> from the elements.</desc>
<signature>
<added>1.4.1</added>
</signature>
<signature>
<added>1.3</added>
<argument name="eventType" type="String">
<desc>A string containing a JavaScript event type, such as <code>click</code> or <code>keydown</code>.</desc>
</argument>
<argument name="handler" optional="true" type="String">
<desc>The function that is no longer to be executed.</desc>
</argument>
</signature>
<signature>
<added>1.4.3</added>
<argument name="events" type="PlainObject">
<desc>A map of one or more event types, such as <code>click</code> or <code>keydown</code> and their corresponding functions that are no longer to be executed.</desc>
</argument>
</signature>
<longdesc>
<p>Any handler that has been attached with <code>.live()</code> can be removed with <code>.die()</code>. This method is analogous to calling <code>.unbind()</code> with no arguments, which is used to remove all handlers attached with <code>.bind()</code>.
See the discussions of <code>.live()</code> and <code>.unbind()</code> for further details.</p>
<p>If used without an argument, .die() removes <em>all</em> event handlers previously attached using <code>.live()</code> from the elements.</p>
<p><strong>As of jQuery 1.7</strong>, use of <code>.die()</code> (and its complementary method, <code>.live()</code>) is not recommended. Instead, use <a href="http://api.jquery.com/off/"><code>.off()</code></a> to remove event handlers bound with <a href="http://api.jquery.com/on/"><code>.on()</code></a></p>
<p><strong>Note:</strong> In order for .die() to function correctly, the selector used with it must match exactly the selector initially used with .live().</p>
</longdesc>
<category slug="events/event-handler-attachment"/>
<category slug="version/1.3"/>
<category slug="version/1.4.1"/>
<category slug="version/1.4.3"/>
<example>
<desc>Can bind and unbind events to the colored button.</desc>
<code><![CDATA[
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...");
});
]]></code>
<css><![CDATA[
button { margin:5px; }
button#theone { color:red; background:yellow; }
]]></css>
<html><![CDATA[<button id="theone">Does nothing...</button>
<button id="bind">Bind Click</button>
<button id="unbind">Unbind Click</button>
<div style="display:none;">Click!</div>]]></html>
</example>
<example>
<desc>To unbind all live events from all paragraphs, write:</desc>
<code><![CDATA[$("p").die()]]></code>
</example>
<example>
<desc>To unbind all live click events from all paragraphs, write:</desc>
<code><![CDATA[$("p").die( "click" )]]></code>
</example>
<example>
<desc>To unbind just one previously bound handler, pass the function in as the second argument:</desc>
<code><![CDATA[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.]]></code>
</example>
<category slug="events/event-handler-attachment"/>
<category slug="version/1.3"/>
<category slug="version/1.4.1"/>
<category slug="version/1.4.3"/>
</entry>