-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathjQueryAPI.en_US.xml
18415 lines (17248 loc) · 844 KB
/
jQueryAPI.en_US.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" ?><api>
<categories>
<category name="Ajax">
<category name="Global Ajax Event Handlers"/>
<category name="Helper Functions"/>
<category name="Low-Level Interface"/>
<category name="Shorthand Methods"/>
</category>
<category name="Attributes"/>
<category name="Core"/>
<category name="CSS"/>
<category name="Data"/>
<category name="Dimensions"/>
<category name="Effects">
<category name="Basics"/>
<category name="Custom"/>
<category name="Fading"/>
<category name="Sliding"/>
</category>
<category name="Events">
<category name="Browser Events"/>
<category name="Document Loading"/>
<category name="Event Handler Attachment"/>
<category name="Event Object"/>
<category name="Form Events"/>
<category name="Keyboard Events"/>
<category name="Mouse Events"/>
</category>
<category name="Forms"/>
<category name="Manipulation">
<category name="Class Attribute"/>
<category name="Copying"/>
<category name="DOM Insertion"/>
<category name="DOM Insertion, Around"/>
<category name="DOM Insertion, Inside"/>
<category name="DOM Insertion, Outside"/>
<category name="DOM Removal"/>
<category name="DOM Replacement"/>
<category name="General Attributes"/>
<category name="Style Properties"/>
</category>
<category name="Miscellaneous">
<category name="Collection Manipulation"/>
<category name="Data Storage"/>
<category name="DOM Element Methods"/>
<category name="Setup Methods"/>
</category>
<category name="Offset"/>
<category name="Internals"/>
<category name="Properties">
<category name="Properties of jQuery Object Instances"/>
<category name="Properties of the Global jQuery Object"/>
</category>
<category name="Selectors">
<category name="Attribute"/>
<category name="Basic"/>
<category name="Basic Filter"/>
<category name="Child Filter"/>
<category name="Content Filter"/>
<category name="Form"/>
<category name="Hierarchy"/>
<category name="Visibility Filter"/>
</category>
<category name="Traversing">
<category name="Filtering"/>
<category name="Miscellaneous Traversing"/>
<category name="Tree Traversal"/>
</category>
<category name="Utilities"/>
<category name="Version">
<category name="Version 1.4.4"/>
<category name="Version 1.4.3"/>
<category name="Version 1.4.2"/>
<category name="Version 1.4.1"/>
<category name="Version 1.4"/>
<category name="Version 1.3"/>
<category name="Version 1.2.6"/>
<category name="Version 1.2.3"/>
<category name="Version 1.2"/>
<category name="Version 1.1.4"/>
<category name="Version 1.1.3"/>
<category name="Version 1.1.2"/>
<category name="Version 1.1"/>
<category name="Version 1.0.4"/>
<category name="Version 1.0"/>
</category>
</categories>
<entries>
<entry type='method' name="fadeToggle" return="jQuery">
<desc>Display or hide the matched elements by animating their opacity.</desc>
<signature>
<added>1.4.4</added>
<argument name="duration" type="String,Number" optional="true">
<desc>A string or number determining how long the animation will run.</desc>
</argument>
<argument name="easing" type="String" optional="true">
<desc>A string indicating which easing function to use for the transition.</desc>
</argument>
<argument name="callback" type="Function" optional="true">
<desc>A function to call once the animation is complete.</desc>
</argument>
</signature>
<longdesc>
<p>The <code>.fadeToggle()</code> method animates the opacity of the matched elements. When called on a visible element, the element's <code>display</code> style property is set to <code>none</code> once the opacity reaches 0, so the element no longer affects the layout of the page.</p>
<p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of <code>200</code> and <code>600</code> milliseconds, respectively.</p>
<p>The string representing an easing function specifies the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called <code>swing</code>, and one that progresses at a constant pace, called <code>linear</code>. More easing functions are available with the use of plug-ins, most notably the <a href="http://jqueryui.com">jQuery UI suite</a>.</p>
<p>If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but <code>this</code> is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole.</p>
</longdesc>
<example>
<desc>Fades first paragraph in or out, completing the animation within 600 milliseconds and using a linear easing. Fades last paragraph in or out for 200 milliseconds, inserting a "finished" message upon completion. </desc>
<code><![CDATA[
$("button:first").click(function() {
$("p:first").fadeToggle("slow", "linear");
});
$("button:last").click(function () {
$("p:last").fadeToggle("fast", function () {
$("#log").append("<div>finished</div>");
});
});
]]></code>
<html><![CDATA[
<button>fadeToggle p1</button>
<button>fadeToggle p2</button>
<p>This paragraph has a slow, linear fade.</p>
<p>This paragraph has a fast animation.</p>
<div id="log"></div>
]]></html>
</example>
<category name="Effects"/>
<category name="Fading"/>
<category name="Version 1.4.4"/>
</entry>
<entry type='method' name="jQuery.type" return="String">
<signature>
<added>1.4.3</added>
<argument name="obj" type="Object">
<desc>Object to get the internal JavaScript [[Class]] of.</desc>
</argument>
</signature>
<desc>Determine the internal JavaScript [[Class]] of an object.</desc>
<longdesc><p>A number of different aspects are utilized to determine the exact return value for an object. The logic can be determined as follows:</p>
<ul>
<li>If the object is undefined or null then "undefined" or "null" is returned accordingly.</li>
<li>If the object has an internal [[Class]] equivalent to one of the browser's built-in objects we return the associated name. (<a href="http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/">More details about this technique.</a>)<ul>
<li>jQuery.type(true) === "boolean"</li>
<li>jQuery.type(3) === "number"</li>
<li>jQuery.type("test") === "string"</li>
<li>jQuery.type(function(){}) === "function"</li>
<li>jQuery.type([]) === "array"</li>
<li>jQuery.type(new Date()) === "date"</li>
<li>jQuery.type(/test/) === "regexp"</li>
</ul></li>
<li>Everything else will return "object" as its type.</li>
</ul>
</longdesc>
<example>
<desc>Finds out if the parameter is a RegExp.</desc>
<code><![CDATA[$("b").append( "" + jQuery.type(/test/) );]]></code>
<html><![CDATA[Is it a RegExp? <b></b>]]></html>
</example>
<category name="Utilities"/>
<category name="Version 1.4.3"/>
</entry>
<entry type='method' name="jQuery.isWindow" return="boolean">
<signature>
<added>1.4.3</added>
<argument name="obj" type="Object">
<desc>Object to test whether or not it is a window.</desc>
</argument>
</signature>
<desc>Determine whether the argument is a window.</desc>
<longdesc><p>This is used in a number of places in jQuery to determine if we're operating against a browser window (such as the current window or an iframe).</p></longdesc>
<example>
<desc>Finds out if the parameter is a window.</desc>
<code><![CDATA[$("b").append( "" + $.isWindow(window) );]]></code>
<html><![CDATA[Is 'window' a window? <b></b>]]></html>
</example>
<category name="Utilities"/>
<category name="Version 1.4.3"/>
</entry>
<entry type='method' name="toggle" return="jQuery">
<desc>Bind two or more handlers to the matched elements, to be executed on alternate clicks.</desc>
<signature>
<added>1.0</added>
<argument name="handler(eventObject)" type="Function">
<desc>A function to execute every even time the element is clicked.</desc>
</argument>
<argument name="handler(eventObject)" type="Function">
<desc>A function to execute every odd time the element is clicked.</desc>
</argument>
<argument name="handler(eventObject)" optional="true" type="Function">
<desc>Additional handlers to cycle through after clicks.</desc>
</argument>
</signature>
<longdesc>
<p>The <code>.toggle()</code> method binds a handler for the <code>click</code> event, so the rules outlined for the triggering of <code>click</code> apply here as well.</p>
<pre>For example, consider the HTML:
<div id="target">
Click here
</div></pre>
<p class="image"><img src="/images/0042_05_05.png" alt="" />
</p>
<p>Event handlers can then be bound to the <code><div></code>:</p>
<pre>$('#target').toggle(function() {
alert('First handler for .toggle() called.');
}, function() {
alert('Second handler for .toggle() called.');
});</pre>
<p>As the element is clicked repeatedly, the messages alternate:</p>
<p>
<span class="output">First handler for .toggle() called.</span><br />
<span class="output">Second handler for .toggle() called.</span><br />
<span class="output">First handler for .toggle() called.</span><br />
<span class="output">Second handler for .toggle() called.</span><br />
<span class="output">First handler for .toggle() called.</span>
</p>
<p>If more than two handlers are provided, <code>.toggle()</code> will cycle among all of them. For example, if there are three handlers, then the first handler will be called on the first click, the fourth click, the seventh click, and so on.</p>
<blockquote><p>Note: jQuery also provides an animation method named <a href="http://api.jquery.com/toggle/">.toggle()</a> that toggles the visibility of elements. Whether the animation or the event method is fired depends on the set of arguments passed.</p></blockquote>
<p>The <code>.toggle()</code> method is provided for convenience. It is relatively straightforward to implement the same behavior by hand, and this can be necessary if the assumptions built into <code>.toggle()</code> prove limiting. For example, <code>.toggle()</code> is not guaranteed to work correctly if applied twice to the same element. Since <code>.toggle()</code> internally uses a <code>click</code> handler to do its work, we must unbind <code>click</code> to remove a behavior attached with <code>.toggle()</code>, so other <code>click</code> handlers can be caught in the crossfire. The implementation also calls <code>.preventDefault()</code> on the event, so links will not be followed and buttons will not be clicked if <code>.toggle()</code> has been called on the element.</p>
</longdesc>
<example>
<desc>Click to toggle highlight on the list item.</desc>
<code><![CDATA[
$("li").toggle(
function () {
$(this).css({"list-style-type":"disc", "color":"blue"});
},
function () {
$(this).css({"list-style-type":"disc", "color":"red"});
},
function () {
$(this).css({"list-style-type":"", "color":""});
}
);
]]></code>
<css><![CDATA[
ul { margin:10px; list-style:inside circle; font-weight:bold; }
li { cursor:pointer; }
]]></css>
<html><![CDATA[<ul>
<li>Go to the store</li>
<li>Pick up dinner</li>
<li>Debug crash</li>
<li>Take a jog</li>
</ul>]]></html>
</example>
<example>
<desc>To toggle a style on table cells:</desc>
<code><![CDATA[$("td").toggle(
function () {
$(this).addClass("selected");
},
function () {
$(this).removeClass("selected");
}
);]]></code>
</example>
<category name="Mouse Events"/>
<category name="Version 1.0"/>
</entry>
<entry type='property' name="jQuery.fx.interval" return="Number">
<desc>The rate (in milliseconds) at which animations fire.</desc>
<signature>
<added>1.4.3</added>
</signature>
<longdesc>
<p>This property can be manipulated to adjust the number of frames per second at which animations will run. The default is 13 milliseconds. Making this a lower number could make the animations run smoother in faster browsers (such as Chrome) but there may be performance and CPU implications of doing so.</p>
<p>Since jQuery uses one global interval, no animation should be running or all animations should stop for the change of this property to take effect.</p>
</longdesc>
<example>
<desc>Cause all animations to run with less frames.</desc>
<code><![CDATA[
jQuery.fx.interval = 100;
$("input").click(function(){
$("div").toggle( 3000 );
});
]]></code>
<css><![CDATA[
div { width:50px; height:30px; margin:5px; float:left;
background:green; }
]]></css>
<html><![CDATA[<p><input type="button" value="Run"/></p>
<div></div>]]></html>
</example>
<category name="Custom"/>
<category name="Properties of the Global jQuery Object"/>
<category name="Version 1.4.3"/>
</entry>
<entry type='property' name="event.namespace" return="String">
<signature>
<added>1.4.3</added>
</signature>
<desc>The namespace specified when the event was triggered.</desc>
<longdesc><p>This will likely be used primarily by plugin authors who wish to handle tasks differently depending on the event namespace used.</p></longdesc>
<example>
<desc>Determine the event namespace used.</desc>
<code><![CDATA[
$("p").bind("test.something", function(event) {
alert( event.namespace );
});
$("button").click(function(event) {
$("p").trigger("test.something");
});
]]></code>
<html><![CDATA[
<button>display event.namespace</button>
<p></p>
]]></html>
</example>
<category name="Event Object"/>
<category name="Version 1.4.3"/>
</entry>
<entry type='method' name="undelegate" return="jQuery">
<desc>Remove a handler from the event for all elements which match the current selector, now or in the future, based upon a specific set of root elements.</desc>
<signature>
<added>1.4.2</added>
</signature>
<signature>
<added>1.4.2</added>
<argument name="selector" type="String">
<desc>A selector which will be used to filter the event results.</desc>
</argument>
<argument name="eventType" type="String">
<desc>A string containing a JavaScript event type, such as "click" or "keydown"</desc>
</argument>
</signature>
<signature>
<added>1.4.2</added>
<argument name="selector" type="String">
<desc>A selector which will be used to filter the event results.</desc>
</argument>
<argument name="eventType" type="String">
<desc>A string containing a JavaScript event type, such as "click" or "keydown"</desc>
</argument>
<argument name="handler" type="Function">
<desc>A function to execute at the time the event is triggered.</desc>
</argument>
</signature>
<longdesc>
<p>Undelegate is a way of removing event handlers that have been bound using <a href="/delegate">.delegate()</a>. It works virtually identically to <a href="/die">.die()</a> with the addition of a selector filter argument (which is required for delegation to work).</p>
</longdesc>
<example>
<desc>Can bind and unbind events to the colored button.</desc>
<code><![CDATA[
function aClick() {
$("div").show().fadeOut("slow");
}
$("#bind").click(function () {
$("body").delegate("#theone", "click", aClick)
.find("#theone").text("Can Click!");
});
$("#unbind").click(function () {
$("body").undelegate("#theone", "click", aClick)
.find("#theone").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 delegated events from all paragraphs, write:</desc>
<code><![CDATA[$("p").undelegate()]]></code>
</example>
<example>
<desc>To unbind all delegated click events from all paragraphs, write:</desc>
<code><![CDATA[$("p").undelegate( "click" )]]></code>
</example>
<example>
<desc>To undelegate just one previously bound handler, pass the function in as the third argument:</desc>
<code><![CDATA[var foo = function () {
// code to handle some kind of event
};
$("body").delegate("p", "click", foo); // ... now foo will be called when paragraphs are clicked ...
$("body").undelegate("p", "click", foo); // ... foo will no longer be called.]]></code>
</example>
<category name="Event Handler Attachment"/>
<category name="Version 1.4.2"/>
</entry>
<entry type='method' name="delegate" return="jQuery">
<desc>Attach a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements.</desc>
<signature>
<added>1.4.2</added>
<argument name="selector" type="String">
<desc>A selector to filter the elements that trigger the event.</desc>
</argument>
<argument name="eventType" type="String">
<desc>A string containing one or more space-separated JavaScript event types, such as "click" or "keydown," or custom event names.</desc>
</argument>
<argument name="handler" type="Function">
<desc>A function to execute at the time the event is triggered.</desc>
</argument>
</signature>
<signature>
<added>1.4.2</added>
<argument name="selector" type="String">
<desc>A selector to filter the elements that trigger the event.</desc>
</argument>
<argument name="eventType" type="String">
<desc>A string containing one or more space-separated JavaScript event types, such as "click" or "keydown," or custom event names.</desc>
</argument>
<argument name="eventData" type="Object">
<desc>A map of data that will be passed to the event handler.</desc>
</argument>
<argument name="handler" type="Function">
<desc>A function to execute at the time the event is triggered.</desc>
</argument>
</signature>
<longdesc>
<p>Delegate is an alternative to using the <a href="/live">.live()</a> method, allowing for each binding of event delegation to specific DOM elements. For example the following delegate code:</p>
<pre>$("table").delegate("td", "hover", function(){
$(this).toggleClass("hover");
});</pre>
<p>Is equivalent to the following code written using <code>.live()</code>:</p>
<pre>$("table").each(function(){
$("td", this).live("hover", function(){
$(this).toggleClass("hover");
});
});</pre>
<p>See also the <a href="/undelegate">.undelegate()</a> method for a way of removing event handlers added in <a href="/delegate">.delegate()</a>.</p>
<p>Passing and handling event data works <a href="http://api.jquery.com/bind/#passing-event-data">the same way as it does for .bind()</a>.</p>
</longdesc>
<example>
<desc>Click a paragraph to add another. Note that .delegate() binds the click event to all paragraphs - even new ones.</desc>
<code><![CDATA[
$("body").delegate("p", "click", function(){
$(this).after("<p>Another paragraph!</p>");
});
]]></code>
<css><![CDATA[
p { background:yellow; font-weight:bold; cursor:pointer;
padding:5px; }
p.over { background: #ccc; }
span { color:red; }
]]></css>
<html><![CDATA[<p>Click me!</p>
<span></span>]]></html>
</example>
<example>
<desc>To display each paragraph's text in an alert box whenever it is clicked:</desc>
<code><![CDATA[$("body").delegate("p", "click", function(){
alert( $(this).text() );
});]]></code>
</example>
<example>
<desc>To cancel a default action and prevent it from bubbling up, return false:</desc>
<code><![CDATA[$("body").delegate("a", "click", function() { return false; })]]></code>
</example>
<example>
<desc>To cancel only the default action by using the preventDefault method.</desc>
<code><![CDATA[$("body").delegate("a", "click", function(event){
event.preventDefault();
});]]></code>
</example>
<example>
<desc>Can bind custom events too.</desc>
<code><![CDATA[
$("body").delegate("p", "myCustomEvent", function(e, myName, myValue){
$(this).text("Hi there!");
$("span").stop().css("opacity", 1)
.text("myName = " + myName)
.fadeIn(30).fadeOut(1000);
});
$("button").click(function () {
$("p").trigger("myCustomEvent");
});
]]></code>
<css><![CDATA[
p { color:red; }
span { color:blue; }
]]></css>
<html><![CDATA[<p>Has an attached custom event.</p>
<button>Trigger custom event</button>
<span style="display:none;"></span>]]></html>
</example>
<category name="Event Handler Attachment"/>
<category name="Version 1.4.2"/>
</entry>
<entry type='method' name="jQuery.error" return="">
<signature>
<added>1.4.1</added>
<argument name="message" type="String">
<desc>The message to send out.</desc>
</argument>
</signature>
<desc>Takes a string and throws an exception containing it.</desc>
<longdesc><p>This method exists primarily for plugin developers who wish to override it and provide a better display (or more information) for the error messages.</p></longdesc>
<example>
<desc>Override jQuery.error for display in Firebug.</desc>
<code><![CDATA[jQuery.error = console.error;]]></code>
</example>
<category name="Internals"/>
<category name="Version 1.4.1"/>
</entry>
<entry type='method' name="jQuery.parseJSON" return="Object">
<signature>
<added>1.4.1</added>
<argument name="json" type="String">
<desc>The JSON string to parse.</desc>
</argument>
</signature>
<desc>Takes a well-formed JSON string and returns the resulting JavaScript object.</desc>
<longdesc><p>Passing in a malformed JSON string may result in an exception being thrown. For example, the following are all malformed JSON strings:</p>
<ul>
<li><code>{test: 1}</code> (test does not have double quotes around it).</li>
<li><code>{'test': 1}</code> ('test' is using single quotes instead of double quotes).</li>
</ul>
<p>Additionally if you pass in nothing, an empty string, null, or undefined, 'null' will be returned from parseJSON. Where the browser provides a native implementation of <code>JSON.parse</code>, jQuery uses it to parse the string. For details on the JSON format, see <a href="http://json.org/">http://json.org/</a>.
</p></longdesc>
<example>
<desc>Parse a JSON string.</desc>
<code><![CDATA[var obj = jQuery.parseJSON('{"name":"John"}');
alert( obj.name === "John" );]]></code>
</example>
<category name="Utilities"/>
<category name="Version 1.4.1"/>
</entry>
<entry type='method' name="jQuery.proxy" return="Function">
<signature>
<added>1.4</added>
<argument name="function" type="Function">
<desc>The function whose context will be changed.</desc>
</argument>
<argument name="context" type="Object">
<desc>The object to which the context (`this`) of the function should be set.</desc>
</argument>
</signature>
<signature>
<added>1.4</added>
<argument name="context" type="Object">
<desc>The object to which the context of the function should be set.</desc>
</argument>
<argument name="name" type="String">
<desc>The name of the function whose context will be changed (should be a property of the 'context' object.</desc>
</argument>
</signature>
<desc>Takes a function and returns a new one that will always have a particular context.</desc>
<longdesc><p>This method is most useful for attaching event handlers to an element where the context is pointing back to a different object. Additionally, jQuery makes sure that even if you bind the function returned from jQuery.proxy() it will still unbind the correct function, if passed the original.</p></longdesc>
<example>
<desc>Enforce the context of the function.</desc>
<code><![CDATA[var obj = {
name: "John",
test: function() {
alert( this.name );
$("#test").unbind("click", obj.test);
}
};
$("#test").click( jQuery.proxy( obj, "test" ) );
// This also works:
// $("#test").click( jQuery.proxy( obj.test, obj ) );]]></code>
</example>
<category name="Event Handler Attachment"/>
<category name="Utilities"/>
<category name="Version 1.4"/>
</entry>
<entry type='method' name="focusout" return="jQuery">
<desc>Bind an event handler to the "focusout" JavaScript event.</desc>
<signature>
<added>1.4</added>
<argument name="handler(eventObject)" type="Function">
<desc>A function to execute each time the event is triggered.</desc>
</argument>
</signature>
<signature>
<added>1.4.3</added>
<argument name="eventData" type="Object" optional="true">
<desc>A map of data that will be passed to the event handler.</desc>
</argument>
<argument name="handler(eventObject)" type="Function">
<desc>A function to execute each time the event is triggered.</desc>
</argument>
</signature>
<longdesc><p>This method is a shortcut for <code>.bind('focusout', handler)</code>.</p>
<p>The <code>focusout</code> event is sent to an element when it, or any element inside of it, loses focus. This is distinct from the <a href="/blur">blur</a> event in that it supports detecting the loss of focus from parent elements (in other words, it supports event bubbling).</p>
<p>This event will likely be used together with the <a href="/focusin">focusin</a> event.</p></longdesc>
<example>
<desc>Watch for a loss of focus to occur inside paragraphs and note the difference between the <code>focusout</code> count and the <code>blur</code> count.</desc>
<css><![CDATA[
.inputs { float: left; margin-right: 1em; }
.inputs p { margin-top: 0; }
]]></css>
<code><![CDATA[
var fo = 0, b = 0;
$("p").focusout(function() {
fo++;
$("#fo")
.text("focusout fired: " + fo + "x");
}).blur(function() {
b++;
$("#b")
.text("blur fired: " + b + "x");
});
]]></code>
<html><![CDATA[
<div class="inputs">
<p>
<input type="text" /><br />
<input type="text" />
</p>
<p>
<input type="password" />
</p>
</div>
<div id="fo">focusout fire</div>
<div id="b">blur fire</div>
]]></html>
</example>
<category name="Keyboard Events"/>
<category name="Mouse Events"/>
<category name="Version 1.4"/>
<category name="Version 1.4.3"/>
</entry>
<entry type='method' name="focusin" return="jQuery">
<desc>Bind an event handler to the "focusin" JavaScript event.</desc>
<signature>
<added>1.4</added>
<argument name="handler(eventObject)" type="Function">
<desc>A function to execute each time the event is triggered.</desc>
</argument>
</signature>
<signature>
<added>1.4.3</added>
<argument name="eventData" type="Object" optional="true">
<desc>A map of data that will be passed to the event handler.</desc>
</argument>
<argument name="handler(eventObject)" type="Function">
<desc>A function to execute each time the event is triggered.</desc>
</argument>
</signature>
<longdesc><p>This method is a shortcut for <code>.bind('focusin', handler)</code>.</p>
<p>The <code>focusin</code> event is sent to an element when it, or any element inside of it, gains focus. This is distinct from the <a href="/focus">focus</a> event in that it supports detecting the focus event on parent elements.</p>
<p>This event will likely be used together with the <a href="/focusout">focusout</a> event.</p></longdesc>
<example>
<desc>Watch for a focus to occur within the paragraphs on the page.</desc>
<css><![CDATA[span {display:none;}]]></css>
<code><![CDATA[
$("p").focusin(function() {
$(this).find("span").css('display','inline').fadeOut(1000);
});
]]></code>
<html><![CDATA[<p><input type="text" /> <span>focusin fire</span></p>
<p><input type="password" /> <span>focusin fire</span></p>]]></html>
</example>
<category name="Keyboard Events"/>
<category name="Mouse Events"/>
<category name="Version 1.4"/>
<category name="Version 1.4.3"/>
</entry>
<entry type='method' name="has" return="jQuery">
<signature>
<added>1.4</added>
<argument name="selector" type="String">
<desc>A string containing a selector expression to match elements against.</desc>
</argument>
</signature>
<signature>
<added>1.4</added>
<argument name="contained" type="Element">
<desc>A DOM element to match elements against.</desc>
</argument>
</signature>
<desc>Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.</desc>
<longdesc>
<p>Given a jQuery object that represents a set of DOM elements, the <code>.has()</code> method constructs a new jQuery object from a subset of the matching elements. The supplied selector is tested against the descendants of the matching elements; the element will be included in the result if any of its descendant elements matches the selector.</p>
<p>Consider a page with a nested list as follows:</p>
<pre>
<ul>
<li>list item 1</li>
<li>list item 2
<ul>
<li>list item 2-a</li>
<li>list item 2-b</li>
</ul>
</li>
<li>list item 3</li>
<li>list item 4</li>
</ul>
</pre>
<p>We can apply this method to the set of list items as follows:</p>
<pre>$('li').has('ul').css('background-color', 'red');</pre>
<p>The result of this call is a red background for item 2, as it is the only <code><li></code> that has a <code><ul></code> among its descendants.</p>
</longdesc>
<example>
<desc>Check if an element is inside another.</desc>
<code><![CDATA[
$("ul").append("<li>" + ($("ul").has("li").length ? "Yes" : "No") + "</li>");
$("ul").has("li").addClass("full");
]]></code>
<css><![CDATA[
.full { border: 1px solid red; }
]]></css>
<html><![CDATA[
<ul><li>Does the UL contain an LI?</li></ul>
]]></html>
</example>
<category name="Filtering"/>
<category name="Version 1.4"/>
</entry>
<entry type='method' name="jQuery.contains" return="Boolean">
<signature>
<added>1.4</added>
<argument name="container" type="Element">
<desc>The DOM element that may contain the other element.</desc>
</argument>
<argument name="contained" type="Element">
<desc>The DOM node that may be contained by the other element.</desc>
</argument>
</signature>
<desc>Check to see if a DOM node is within another DOM node.</desc>
<longdesc></longdesc>
<example>
<desc>Check if an element is inside another.</desc>
<code><![CDATA[jQuery.contains(document.documentElement, document.body); // true
jQuery.contains(document.body, document.documentElement); // false]]></code>
</example>
<category name="Utilities"/>
<category name="Version 1.4"/>
</entry>
<entry type='method' name="jQuery.noop" return="Function">
<signature><added>1.4</added></signature>
<desc>An empty function.</desc>
<longdesc><p>You can use this empty function when you wish to pass around a function that will do nothing.</p>
<p>This is useful for plugin authors who offer optional callbacks; in the case that no callback is given, something like <code>jQuery.noop</code> could execute.</p></longdesc>
<category name="Utilities"/>
<category name="Version 1.4"/>
</entry>
<entry type='method' name="delay" return="jQuery">
<signature>
<added>1.4</added>
<argument name="duration" type="Integer">
<desc>An integer indicating the number of milliseconds to delay execution of the next item in the queue.</desc>
</argument>
<argument name="queueName" optional="true" type="String">
<desc>A string containing the name of the queue. Defaults to <code>fx</code>, the standard effects queue.</desc>
</argument>
</signature>
<desc>Set a timer to delay execution of subsequent items in the queue.</desc>
<longdesc><p>Added to jQuery in version 1.4, the <code>.delay()</code> method allows us to delay the execution of functions that follow it in the queue. It can be used with the standard effects queue or with a custom queue. Only subsequent events in a queue are delayed; for example this will <em>not</em> delay the no-arguments forms of <code>.show()</code> or <code>.hide()</code> which do not use the effects queue.</p>
<p>Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings <code>'fast'</code> and <code>'slow'</code> can be supplied to indicate durations of 200 and 600 milliseconds, respectively.</p>
<p>Using the standard effects queue, we can, for example, set an 800-millisecond delay between the <code>.slideUp()</code> and <code>.fadeIn()</code> of <code><div id="foo"></code>:</p>
<pre>$('#foo').slideUp(300).delay(800).fadeIn(400);</pre>
<p>When this statement is executed, the element slides up for 300 milliseconds and then pauses for 800 milliseconds before fading in for 400 milliseconds.</p>
<blockquote><p><strong>The <code>.delay()</code> method is best for delaying between queued jQuery effects. Because it is limited—it doesn't, for example, offer a way to cancel the delay—<code>.delay()</code> is not a replacement for JavaScript's native <a href="https://developer.mozilla.org/en/DOM/window.setTimeout">setTimeout</a> function, which may be more appropriate for certain use cases.</strong></p></blockquote>
</longdesc>
<example>
<desc>Animate the hiding and showing of two divs, delaying the first before showing it.</desc>
<css><![CDATA[
div { width: 60px; height: 60px; float: left; }
.first { background-color: #3f3; }
.second { background-color: #33f;}]]>
</css>
<code><![CDATA[
$("button").click(function() {
$("div.first").slideUp(300).delay(800).fadeIn(400);
$("div.second").slideUp(300).fadeIn(400);
});]]>
</code>
<html><![CDATA[
<p><button>Run</button></p>
<div class="first"></div>
<div class="second"></div>]]>
</html>
</example>
<category name="Custom"/>
<category name="Version 1.4"/>
</entry>
<entry type='method' name="parentsUntil" return="jQuery">
<signature>
<added>1.4</added>
<argument name="selector" optional="true" type="Selector">
<desc>A string containing a selector expression to indicate where to stop matching ancestor elements.</desc>
</argument>
</signature>
<desc>Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector.</desc>
<longdesc><p>Given a jQuery object that represents a set of DOM elements, the <code>.parentsUntil()</code> method traverses through the ancestors of these elements until it reaches an element matched by the selector passed in the method's argument. The resulting jQuery object contains all of the ancestors up to but not including the one matched by the <code>.parentsUntil()</code> selector. Consider a page with a basic nested list as follows:</p>
<pre><ul class="level-1">
<li class="item-i">I</li>
<li class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
<li class="item-3">3</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>
</pre>
<p>If we begin at item A, we can find its ancestors up to but not including <code><ul class="level-1"></code> as follows:</p>
<pre>$('li.item-a').parentsUntil('.level-1')
.css('background-color', 'red');</pre>
<p>The result of this call is a red background for the level-2 list and the item II. </p>
<p>If the .parentsUntil() selector is not matched, or if no selector is supplied, the returned jQuery object contains all of the previous jQuery object's ancestors. For example, let's say we begin at item A again, but this time we use a selector that is not matched by any of its ancestors:</p>
<pre>$('li.item-a').parentsUntil('.not-here')
.css('background-color', 'red');</pre>
<p>The result of this call is a red background-color style applied to the level-2 list, the item II, the level-1 list, the <code><body></code> element, and the <code><html></code> element.</p>
</longdesc>
<example>
<desc>Find the ancestors of <li class="item-a"> up to <ul class="level-1"> and give them a red background color.</desc>
<code><![CDATA[
$('li.item-a').parentsUntil('.level-1')
.css('background-color', 'red');
]]></code>
<html><![CDATA[
<ul class="level-1">
<li class="item-i">I</li>
<li class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
<li class="item-3">3</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>]]></html>
</example>
<category name="Tree Traversal"/>
<category name="Version 1.4"/>
</entry>
<entry type='method' name="prevUntil" return="jQuery">
<signature>
<added>1.4</added>
<argument name="selector" optional="true" type="Selector">
<desc>A string containing a selector expression to indicate where to stop matching preceding sibling elements.</desc>
</argument>
</signature>
<desc>Get all preceding siblings of each element up to but not including the element matched by the selector.</desc>
<longdesc><p>Given a jQuery object that represents a set of DOM elements, the <code>.prevUntil()</code> method allows us to search through the predecessors of these elements in the DOM tree, stopping when it reaches an element matched by the method's argument. The new jQuery object that is returned contains all previous siblings up to but not including the one matched by the <code>.prevUntil()</code> selector.</p>
<p>If the selector is not matched or is not supplied, all previous siblings will be selected; in these cases it selects the same elements as the <code>.prevAll()</code> method does when no filter selector is provided.</p>
<p>Consider a page with a simple definition list as follows:</p>
<pre>
<dl>
<dt>term 1</dt>
<dd>definition 1-a</dd>
<dd>definition 1-b</dd>
<dd>definition 1-c</dd>
<dd>definition 1-d</dd>
<dt id="term-2">term 2</dt>
<dd>definition 2-a</dd>
<dd>definition 2-b</dd>
<dd>definition 2-c</dd>
<dt>term 3</dt>
<dd>definition 3-a</dd>
<dd>definition 3-b</dd>
</dl>
</pre>
<p>If we begin at the second term, we can find the elements which come after it until a preceding <code><dt></code>.</p>
<pre>$('#term-2').prevUntil('dt').css('background-color', 'red');</pre>
<p>The result of this call is a red background behind definitions <code>1-a</code>, <code>1-b</code>, <code>1-c</code>, and <code>1-d</code>. </p>
</longdesc>
<example>
<desc>Find the siblings that precede <dt id="term-2"> up to the preceding <dt> and give them a red background color.</desc>
<code><![CDATA[
$("#term-2").prevUntil("dt")
.css("background-color", "red")
]]></code>
<html><![CDATA[<dl>
<dt>term 1</dt>
<dd>definition 1-a</dd>
<dd>definition 1-b</dd>
<dd>definition 1-c</dd>
<dd>definition 1-d</dd>
<dt id="term-2">term 2</dt>
<dd>definition 2-a</dd>
<dd>definition 2-b</dd>
<dd>definition 2-c</dd>
<dt>term 3</dt>
<dd>definition 3-a</dd>
<dd>definition 3-b</dd>
</dl>]]></html>
</example>
<category name="Tree Traversal"/>
<category name="Version 1.4"/>
</entry>
<entry type='method' name="nextUntil" return="jQuery">
<signature>
<added>1.4</added>
<argument name="selector" optional="true" type="Selector">
<desc>A string containing a selector expression to indicate where to stop matching following sibling elements.</desc>
</argument>
</signature>
<desc>Get all following siblings of each element up to but not including the element matched by the selector.</desc>
<longdesc><p>Given a jQuery object that represents a set of DOM elements, the <code>.nextUntil()</code> method allows us to search through the successors of these elements in the DOM tree, stopping when it reaches an element matched by the method's argument. The new jQuery object that is returned contains all following siblings up to but not including the one matched by the <code>.nextUntil()</code> selector.</p>
<p>If the selector is not matched or is not supplied, all following siblings will be selected; in these cases it selects the same elements as the <code>.nextAll()</code> method does when no filter selector is provided.</p>
<p>Consider a page with a simple definition list as follows:</p>
<pre>
<dl>
<dt>term 1</dt>
<dd>definition 1-a</dd>
<dd>definition 1-b</dd>
<dd>definition 1-c</dd>
<dd>definition 1-d</dd>
<dt id="term-2">term 2</dt>
<dd>definition 2-a</dd>
<dd>definition 2-b</dd>
<dd>definition 2-c</dd>
<dt>term 3</dt>
<dd>definition 3-a</dd>
<dd>definition 3-b</dd>
</dl>
</pre>
<p>If we begin at the second term, we can find the elements which come after it until a following <code><dt></code>.</p>
<pre>$('#term-2').nextUntil('dt').css('background-color', 'red');</pre>
<p>The result of this call is a red background behind definitions <code>2-a</code>, <code>2-b</code>, and <code>2-c</code>. </p>
</longdesc>
<example>
<desc>Find the siblings that follow <dt id="term-2"> up to the next <dt> and give them a red background color.</desc>
<code><![CDATA[
$("#term-2").nextUntil("dt")
.css("background-color", "red")
]]></code>
<html><![CDATA[<dl>
<dt>term 1</dt>
<dd>definition 1-a</dd>
<dd>definition 1-b</dd>
<dd>definition 1-c</dd>
<dd>definition 1-d</dd>
<dt id="term-2">term 2</dt>
<dd>definition 2-a</dd>
<dd>definition 2-b</dd>
<dd>definition 2-c</dd>
<dt>term 3</dt>
<dd>definition 3-a</dd>
<dd>definition 3-b</dd>
</dl>]]></html>
</example>
<category name="Tree Traversal"/>
<category name="Version 1.4"/>
</entry>
<entry type='method' name="event.isImmediatePropagationStopped" return="Boolean">
<signature>
<added>1.3</added>
</signature>
<desc> Returns whether event.stopImmediatePropagation() was ever called on this event object. </desc>
<longdesc> <p>This property was introduced in <a href="http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-Event-isImmediatePropagationStopped">DOM level 3</a>.</p> </longdesc>
<example>
<desc>Checks whether event.stopImmediatePropagation() was called.</desc>
<code><![CDATA[
function immediatePropStopped(e) {
var msg = "";
if ( e.isImmediatePropagationStopped() ) {
msg = "called"
} else {
msg = "not called";
}
$("#stop-log").append( "<div>" + msg + "</div>" );
}
$("button").click(function(event) {