You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: entries/data.xml
+70-52
Original file line number
Diff line number
Diff line change
@@ -23,13 +23,12 @@
23
23
<p>The <code>.data()</code> method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks.</p>
24
24
<p> We can set several distinct values for a single element and retrieve them later:</p>
<p>In jQuery 1.4.3 setting an element's data object with <code>.data(obj)</code> extends the data previously stored with that element. jQuery itself uses the <code>.data()</code> method to save information under the names 'events' and 'handle', and also reserves any data name starting with an underscore ('_') for internal use.</p>
34
33
<p>Prior to jQuery 1.4.3 (starting in jQuery 1.4) the .data() method completely replaced all data, instead of just extending the data object. If you are using third-party plugins it may not be advisable to completely replace the element's data object, since plugins may have also set data.</p>
35
34
<p>Due to the way browsers interact with plugins and external code, the <code>.data()</code> method cannot be used on <code><object></code> (unless it's a Flash plugin), <code><applet></code> or <code><embed></code> elements.</p>
<p>The <code>.data()</code> method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks. We can retrieve several distinct values for a single element one at a time, or as a set:</p>
75
80
<pre><code>
76
-
alert($('body').data('foo'));
77
-
alert($('body').data());
78
-
</code></pre>
81
+
alert( $( "body" ).data( "foo" ) );
82
+
alert( $( "body" ).data());
83
+
</code></pre>
79
84
<p>The above lines alert the data values that were set on the <code>body</code> element. If no data at all was set on that element, <code>undefined</code> is returned.</p>
80
85
<pre><code>
81
-
alert( $("body").data("foo")); //undefined
82
-
$("body").data("bar", "foobar");
83
-
alert( $("body").data("bar")); //foobar
84
-
</code></pre>
86
+
alert( $("body").data("foo" ) ); //undefined
87
+
$("body").data("bar", "foobar");
88
+
alert( $("body").data("bar" ) ); //foobar
89
+
</code></pre>
85
90
<h4id="data-html5">
86
91
<ahref="#data-html5">HTML5 data-* Attributes</a>
87
92
</h4>
88
93
<p>As of jQuery 1.4.3 <ahref="http://ejohn.org/blog/html-5-data-attributes/">HTML 5 data- attributes</a> will be automatically pulled in to jQuery's data object. The treatment of attributes with embedded dashes was changed in jQuery 1.6 to conform to the <ahref="http://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes">W3C HTML5 specification</a>.</p>
<p>Every attempt is made to convert the string to a JavaScript value (this includes booleans, numbers, objects, arrays, and null). A value is only converted to a number if doing so doesn't change the value's representation. For example, "1E02" and "100.000" are equivalent as numbers (numeric value 100) but converting them would alter their representation so they are left as strings. The string value "100" is converted to the number 100.</p>
97
104
<p>When the data attribute is an object (starts with '{') or array (starts with '[') then <code>jQuery.parseJSON</code> is used to parse the string; it must follow <ahref="http://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_example">valid JSON syntax</a> <em>including quoted property names</em>. If the value isn't parseable as a JavaScript value, it is left as a string.</p>
98
105
<p>To retrieve the value's attribute as a string without any attempt to convert it, use the <code><ahref="/attr/">attr()</a></code> method.</p>
99
106
<p>The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery).</p>
100
107
<p>Calling <code>.data()</code> with no parameters retrieves all of the values as a JavaScript object. This object can be safely cached in a variable as long as a new object is not set with <code>.data(obj)</code>. Using the object directly to get or set values is faster than making individual calls to <code>.data()</code> to get or set each value:</p>
101
108
<pre><code>
102
-
var mydata = $("#mydiv").data();
109
+
var mydata = $("#mydiv").data();
103
110
if ( mydata.count < 9 ) {
104
-
mydata.count = 43;
105
-
mydata.status = "embiggened";
111
+
mydata.count = 43;
112
+
mydata.status = "embiggened";
106
113
}
107
-
</code></pre>
114
+
</code></pre>
108
115
</longdesc>
109
116
<noteid="no-data-on-xml"type="additional"/>
110
117
<example>
111
118
<desc>Get the data named "blah" stored at for an element.</desc>
112
119
<code><![CDATA[
113
-
$("button").click(function(e) {
120
+
$("button").click(function( e ) {
114
121
var value;
115
122
116
-
switch ($("button").index(this)) {
123
+
switch ( $( "button").index(this ) ) {
117
124
case 0 :
118
-
value = $("div").data("blah");
125
+
value = $("div").data("blah");
119
126
break;
120
127
case 1 :
121
-
$("div").data("blah", "hello");
128
+
$("div").data("blah", "hello");
122
129
value = "Stored!";
123
130
break;
124
131
case 2 :
125
-
$("div").data("blah", 86);
132
+
$("div").data("blah", 86);
126
133
value = "Stored!";
127
134
break;
128
135
case 3 :
129
-
$("div").removeData("blah");
136
+
$("div").removeData("blah");
130
137
value = "Removed!";
131
138
break;
132
139
}
133
140
134
-
$("span").text("" + value);
141
+
$("span").text("" + value);
135
142
});
136
-
137
143
]]></code>
138
144
<css><![CDATA[
139
-
div { margin:5px; background:yellow; }
140
-
button { margin:5px; font-size:14px; }
141
-
p { margin:5px; color:blue; }
142
-
span { color:red; }
145
+
div {
146
+
margin: 5px;
147
+
background: yellow;
148
+
}
149
+
button {
150
+
margin: 5px;
151
+
font-size: 14px;
152
+
}
153
+
p {
154
+
margin: 5px;
155
+
color: blue;
156
+
}
157
+
span {
158
+
color: red;
159
+
}
143
160
]]></css>
144
-
<html><![CDATA[<div>A div</div>
145
-
<button>Get "blah" from the div</button>
146
-
<button>Set "blah" to "hello"</button>
147
-
148
-
<button>Set "blah" to 86</button>
149
-
<button>Remove "blah" from the div</button>
150
-
<p>The "blah" value of this div is <span>?</span></p>]]></html>
161
+
<html><![CDATA[
162
+
<div>A div</div>
163
+
<button>Get "blah" from the div</button>
164
+
<button>Set "blah" to "hello"</button>
165
+
<button>Set "blah" to 86</button>
166
+
<button>Remove "blah" from the div</button>
167
+
<p>The "blah" value of this div is <span>?</span></p>
Copy file name to clipboardExpand all lines: entries/dblclick.xml
+36-20
Original file line number
Diff line number
Diff line change
@@ -21,30 +21,36 @@
21
21
<added>1.0</added>
22
22
</signature>
23
23
<longdesc>
24
-
<p>This method is a shortcut for <code>.on('dblclick', handler)</code> in the first two variations, and <code>.trigger('dblclick')</code> in the third.
24
+
<p>This method is a shortcut for <code>.on( "dblclick", handler)</code> in the first two variations, and <code>.trigger( "dblclick" )</code> in the third.
25
25
The <code>dblclick</code> event is sent to an element when the element is double-clicked. Any HTML element can receive this event.
26
26
For example, consider the HTML:</p>
27
-
<pre><code><div id="target">
27
+
<pre><code>
28
+
<div id="target">
28
29
Double-click here
29
30
</div>
30
31
<div id="other">
31
32
Trigger the handler
32
-
</div></code></pre>
33
+
</div>
34
+
</code></pre>
33
35
<pclass="image">
34
36
<imgsrc="/resources/0042_05_04.png"alt=""/>
35
37
</p>
36
38
<p>The event handler can be bound to any <code><div></code>:</p>
37
-
<pre><code>$('#target').dblclick(function() {
38
-
alert('Handler for .dblclick() called.');
39
-
});</code></pre>
39
+
<pre><code>
40
+
$( "#target" ).dblclick(function() {
41
+
alert( "Handler for .dblclick() called." );
42
+
});
43
+
</code></pre>
40
44
<p>Now double-clicking on this element displays the alert:</p>
41
45
<p>
42
46
<samp>Handler for .dblclick() called.</samp>
43
47
</p>
44
48
<p>To trigger the event manually, apply <code>.dblclick()</code> without an argument:</p>
45
-
<pre><code>$('#other').click(function() {
46
-
$('#target').dblclick();
47
-
});</code></pre>
49
+
<pre><code>
50
+
$( "#other" ).click(function() {
51
+
$( "#target" ).dblclick();
52
+
});
53
+
</code></pre>
48
54
<p>After this code executes, (single) clicks on <samp>Trigger the handler</samp> will also alert the message.</p>
49
55
<p>The <code>dblclick</code> event is only triggered after this exact series of events:</p>
50
56
<ul>
@@ -58,25 +64,35 @@
58
64
</longdesc>
59
65
<example>
60
66
<desc>To bind a "Hello World!" alert box the dblclick event on every paragraph on the page:</desc>
61
-
<code><![CDATA[$("p").dblclick( function () { alert("Hello World!"); });]]></code>
67
+
<code><![CDATA[
68
+
$( "p" ).dblclick( function () {
69
+
alert( "Hello World!" );
70
+
});
71
+
]]></code>
62
72
</example>
63
73
<example>
64
74
<desc>Double click to toggle background color.</desc>
65
75
<code><![CDATA[
66
-
var divdbl = $("div:first");
67
-
divdbl.dblclick(function () {
68
-
divdbl.toggleClass('dbl');
69
-
});
76
+
var divdbl = $("div:first");
77
+
divdbl.dblclick(function () {
78
+
divdbl.toggleClass( "dbl" );
79
+
});
70
80
]]></code>
71
81
<css><![CDATA[
72
-
div { background:blue;
73
-
color:white;
74
-
height:100px;
75
-
width:150px;
82
+
div {
83
+
background: blue;
84
+
color: white;
85
+
height: 100px;
86
+
width: 150px;
76
87
}
77
-
div.dbl { background:yellow;color:black; }
88
+
div.dbl {
89
+
background: yellow;
90
+
color: black;
91
+
}
78
92
]]></css>
79
-
<html><![CDATA[<div></div><span>Double click the block</span>]]></html>
Copy file name to clipboardExpand all lines: entries/deferred.always.xml
+3-3
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,9 @@
21
21
<example>
22
22
<desc>Since the <ahref="http://api.jquery.com/jQuery.get/"><code>jQuery.get()</code></a> method returns a <code>jqXHR</code> object, which is derived from a Deferred object, we can attach a callback for both success and error using the <code>deferred.always()</code> method.</desc>
23
23
<code><![CDATA[
24
-
$.get("test.php").always(function() {
25
-
alert("$.get completed with success or error callback arguments");
26
-
});
24
+
$.get("test.php").always(function() {
25
+
alert("$.get completed with success or error callback arguments");
Copy file name to clipboardExpand all lines: entries/deferred.done.xml
+14-14
Original file line number
Diff line number
Diff line change
@@ -21,8 +21,8 @@
21
21
<example>
22
22
<desc>Since the <ahref="/jQuery.get"><code>jQuery.get</code></a> method returns a jqXHR object, which is derived from a Deferred object, we can attach a success callback using the <code>.done()</code> method.</desc>
Copy file name to clipboardExpand all lines: entries/deferred.fail.xml
+7-3
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,13 @@
21
21
<example>
22
22
<desc>Since the <ahref="http://api.jquery.com/jQuery.get/"><code>jQuery.get</code></a> method returns a jqXHR object, which is derived from a Deferred, you can attach a success and failure callback using the <code>deferred.done()</code> and <code>deferred.fail()</code> methods.</desc>
0 commit comments