This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
forked from aristus/jquery-yui3-rosetta-stone
-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.html
1698 lines (1539 loc) · 48.3 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery - YUI 3 Rosetta Stone</title>
<link rel="stylesheet" type="text/css" href="css/rosetta.css">
</head>
<body>
<h1>jQuery - YUI 3 Rosetta Stone</h1>
<p class="printonly">
<a href="http://www.jsrosettastone.com/">www.jsrosettastone.com</a>
</p>
<ul class="toc">
<li><a href="#start">Getting Started</a></li>
<li><a href="#common">Common Idioms</a></li>
<li><a href="#events">Events</a></li>
<li><a href="#selectors">Selectors</a></li>
<li><a href="#effects">Animations & Effects</a></li>
<li>
<a href="#nodelist">Array vs. NodeList</a>
<!--
TODO: Figure out a better place for summaries like this. And make them visible.
<p class="gloss">The fundamental unit of jQuery is a JavaScript Array containing 0 or more DOM elements. These Array objects have extra <code>.on()</code>, <code>.click()</code>, <code>.map()</code>, etc methods attached to them in addition to the built-in list operations like <code>.slice()</code> and <code>.concat()</code>. </p>
<p class="gloss">The fundamental units in YUI are <a href="http://developer.yahoo.com/yui/3/api/Node.html">Node</a> objects, which wrap DOM elements, and <a href="http://developer.yahoo.com/yui/3/api/NodeList.html">NodeList</a>s which are collections of Nodes. NodeLists are not Arrays and are not natively iterable.</p>
-->
</li>
<li><a href="#ajax">Ajax</a></li>
<li><a href="#css">CSS</a></li>
<li><a href="#credits">Credits</a></li>
<li class="screenonly"><a href="#contrib">How to Contribute</a></li>
</ul>
<h2 id="start">Getting Started</h2>
<table>
<thead>
<tr>
<th class="jq">jQuery 1.8.3</th>
<th class="yui">YUI 3.8.0</th>
</tr>
</thead>
<tbody>
<tr>
<td class="code">
<pre class="code jq">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://somedomain.com/path/to/plugin.js"></script>
<script src="https://somedomain.com/path/to/anotherplugin.js"></script>
<script>
$(document).ready(function() {
// Do stuff with the $ object here
$<i>.foo.bar()</i>
});
</script>
</pre>
<p><strong>Loading Method</strong>: Statically loaded (by default).</p>
<p><strong>Scope</strong>: The <code>jQuery</code>/<code>$</code> objects are global.</p>
<p><strong>Plugins</strong>: To go beyond base library functionality, jQuery has the concept of "plugins" which are loaded in via additional <code><script></code> tags, or a dynamic loader. All examples on this page use core library methods (no plugins).<p>
</td>
<td class="code">
<pre class="code yui">
<script src="http://yui.yahooapis.com/3.8.0/build/yui/yui-min.js"></script>
<script>
YUI().use('<i>module1</i>', '<i>module2</i>', '<i>module3</i>', function (Y) {
// Do stuff with the Y object here
Y<i>.foo.bar()</i>
});
</script>
</pre>
<p><strong>Loading Method</strong>: Dynamically loaded (by default).</p>
<p><strong>Scope</strong>: The <code>YUI</code> loader object is global, and the <code>Y</code> object is local to each "sandbox" (your callback function). However, the return value of <code>YUI().use()</code> is a <code>Y</code> object, which you can assign to a global variable [e.g. <code class="nowrap">var Y = YUI().use(…);</code>].</p>
<p><strong>Modules</strong>: Functionality in the YUI library is provided by "modules", which are split between <a href="http://yuilibrary.com/yui/docs/guides/">core</a> (officially supported) and <a href="http://yuilibrary.com/gallery/show">gallery</a> (user contributed). Simply adding <code>YUI().use(function(Y){});</code> doesn't get you much, so you will need to specify which modules you wish to use and the loader will fetch them for you. The following core modules should provide you all the functionality for the examples in this document: </p>
<pre>
YUI().use('node', 'io', 'event', 'animation', function (Y) {
// example code here
});
</pre>
<p>If any additional modules are needed, they'll be specified in the "notes" section to the example.</p>
</td>
</tr>
</tbody>
</table>
<h2 id="common" class="section">Common Idioms</h2>
<table>
<thead>
<tr>
<th class="jq">jQuery 1.8.3</th>
<th class="yui">YUI 3.8.0</th>
<th class="notes">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td class="code">
<pre class="code jq">$('div.foo:first')</pre>
</td>
<td class="code">
<pre class="code yui">Y.one('div.foo')</pre>
</td>
<td class="notes">
<p>jQuery and YUI use similar selector syntax, but jQuery has added extensions, mainly convenience pseudo-classes, to the Sizzle CSS3-compliant selector engine. YUI comes with three different selector engines; see the section on <a href="#selectors">Selectors</a>.
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
var foo = $('div.foo:first');
foo.<i>some_method()</i>;
</pre>
</td>
<td class="code">
<pre class="code yui">
var foo = Y.one('div.foo');
if (foo) {
foo.<i>some_method()</i>;
}
</pre>
</td>
<td class="notes">
<p>Return the first element which matches the selector. <code>:first</code> is a jQuery extension.</p>
<p>If no elements match, <code>Y.one()</code> returns <code>null</code> and you should check for it. jQuery selector methods always return a list object with 0 or more elements.<p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">$('div.foo')</pre>
</td>
<td class="code">
<pre class="code yui">Y.all('div.foo')</pre>
</td>
<td class="notes">
<p>Select all div elements with a class of foo.<p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
var foo = $('div.foo');
if (foo.length) {
<i>// do something</i>
}
</pre>
</td>
<td class="code">
<pre class="code yui">
var foo = Y.all('div.foo');
if (foo.size()) {
<i>// do something</i>
}
</pre>
</td>
<td class="notes">
<p>If no elements match the selector, <code>Y.all()</code> returns an empty <code>NodeList</code> object. jQuery will return an empty list <code>[]</code> that is loaded with special jQ methods. Both are <a href="http://javascript.crockford.com/style2.html">truthy</a> even if they contain no elements, so use <code>NodeList.size()</code> and <code>[].length</code> to check for emptiness.<p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.find('p.foo:first')
.find('p.foo')
</pre>
</td>
<td class="code">
<pre class="code yui">
.one('p.foo')
.all('p.foo')
</pre>
</td>
<td class="notes"><p>Finds <code>P</code> elements with class <code>foo</code> that are children of the given node.<p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">$('<div/>')</pre>
</td>
<td class="code">
<pre class="code yui">Y.Node.create('<div/>')</pre>
</td>
<td class="notes"><p>Create a new DOM element. Does not add it to the document tree.<p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.html('<i>foo</i>')
.text('<i>foo</i>')
.val('<i>foo</i>')
</pre>
</td>
<td class="code">
<pre class="code yui">
.setHTML('<i>foo</i>')
.set('text', '<i>foo</i>')
.set('value', '<i>foo</i>')
</pre>
</td>
<td class="notes">
<p><code>.set()</code> is a generic method in YUI for modifying element object properties. Use <code>.setAttribute()</code> to modify element attributes.<p>
<p><code>.setHTML(<i>html</i>)</code> is a convenience wrapper around <code>.set('innerHTML', <i>html</i>)</code><p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.html()
.text()
.val()
</pre>
</td>
<td class="code">
<pre class="code yui">
.getHTML()
.get('text')
.get('value')
</pre>
</td>
<td class="notes">
<p>jQuery tends to overload getters and setters in the same method.</p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.attr('<i>foo</i>')
.attr('<i>foo</i>', '<i>bar</i>')
</pre>
</td>
<td class="code">
<pre class="code yui">
.getAttribute('<i>foo</i>')
.setAttribute('<i>foo</i>', '<i>bar</i>')
</pre>
</td>
<td class="notes">
<p>Generic HTML attribute getters and setters.</p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
$.trim('<i> foo </i>')
</pre>
</td>
<td class="code">
<pre class="code yui">
Y.Lang.trim('<i> foo </i>')
</pre>
</td>
<td class="notes">
<p>Strips leading and trailing whitespace.</p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq"><i>parent</i>.append('<div/>')</pre>
</td>
<td class="code">
<pre class="code yui"><i>parent</i>.append('<div/>')</pre>
</td>
<td class="notes">
<p>Creates a new div element and makes it a child of <code>parent</code>.<p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq"><i>child</i>.appendTo(<i>parent</i>)</pre>
</td>
<td class="code">
<pre class="code yui">
<i>child</i>.appendTo(<i>parent</i>)
</pre>
</td>
<td class="notes">
<p>Appends <code>child</code> to <code>parent</code>, and returns <code>child</code>.</p>
<p><code>.appendTo()</code> was added to YUI in 3.3.0.</code></p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
<i>parent</i> = $('<div/>');
$('<p>foo<p>')
.click(<i>fn</i>)
.appendTo(<i>parent</i>);
</pre>
</td>
<td class="code">
<pre class="code yui">
<i>parent</i> = Y.Node.create('<div/>');
Y.Node.create('<p>foo</p>')
.appendTo(<i>parent</i>)
.on('click', <i>fn</i>);
</pre>
</td>
<td class="notes">
Creates a new <code>div</code> element, then appends a <code>p</code> element with a <code>click</code> event subscription. Note that YUI's <code>on()</code> method is not chainable, so it returns an event handle, not the <code>p</code> node.
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.replaceWith(<i>content</i>);
</pre>
</td>
<td class="code">
<pre class="code yui">
.insert(<i>content</i>, 'replace');
</pre>
</td>
<td class="notes">
Replace the specified node with <code>content</code>.
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.before(<i>content</i>);
</pre>
</td>
<td class="code">
<pre class="code yui">
.insert(<i>content</i>, 'before');
</pre>
</td>
<td class="notes">
Insert <code>content</code> before the specified node.
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.after(<i>content</i>);
</pre>
</td>
<td class="code">
<pre class="code yui">
.insert(<i>content</i>, 'after');
</pre>
</td>
<td class="notes">
Insert <code>content</code> after the specified node.
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
<i>// Removes #foo from its parent and
// detaches events and jQuery data.</i>
$('#foo').remove()
<i>// Removes #foo from #container.</i>
$('#container').remove('#foo')
</pre>
</td>
<td class="code">
<pre class="code yui">
<i>// Removes #foo from its parent, but doesn't
// detach events or YUI plugins.</i>
Y.one('#foo').remove()
<i>// Removes #foo and detaches events and plugins.</i>
Y.one('#foo').remove(<i>true</i>)
<i>// Removes #foo from #container.</i>
Y.one('#container').removeChild(Y.one('#foo'))
</pre>
</td>
<td class="notes">
<p>
jQuery's <code>.remove()</code> purges events and jQuery data from the removed node. For the equivalent behavior in YUI, use <code>.remove(<i>true</i>)</code>.
</p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">.empty()</pre>
</td>
<td class="code">
<pre class="code yui">.empty()</pre>
</td>
<td class="notes">
<p>
Removes and destroys all of the nodes within the given node and also deregisters any events associated with the elements being destroyed.
<p>
<p>
<code>.empty()</code> was added to YUI in 3.3.0.
</p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.siblings()
.siblings(<i>selector</i>)
</pre>
</td>
<td class="code">
<pre class="code yui">
.siblings()
.siblings(<i>selector</i>)
.siblings(<i>function</i>)
</pre>
</td>
<td class="notes">
<p>
In addition to an optional selector string, YUI also supports passing
a function to filter the returned siblings.
<p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.next()
.next(<i>selector</i>)
</pre>
</td>
<td class="code">
<pre class="code yui">
.next()
.next(<i>selector</i>)
.next(<i>fn</i>)
</pre>
</td>
<td class="notes">
<p>
Same considerations as <code>.siblings()</code>.
<p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.prev()
.prev(<i>selector</i>)
</pre>
</td>
<td class="code">
<pre class="code yui">
.previous()
.previous(<i>selector</i>)
.previous(<i>fn</i>)
</pre>
</td>
<td class="notes">
<p>
Same considerations as <code>.siblings()</code>.
<p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.parent()
</pre>
</td>
<td class="code">
<pre class="code yui">
.get('parentNode')
</pre>
</td>
<td class="notes"><p>Returns the parent node of the given node.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.children()
</pre>
</td>
<td class="code">
<pre class="code yui">
.get('children')
</pre>
</td>
<td class="notes"><p>Returns all the element children of the given node.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.closest(<i>selector</i>)
</pre>
</td>
<td class="code">
<pre class="code yui">
.ancestor(<i>selector</i>)
.ancestor(<i>fn</i>)
</pre>
</td>
<td class="notes"><p>Returns the first ancestor that matches the given selector. In addition, YUI supports using a function instead of a selector to find an ancestor.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
$.contains(<i>node</i>, <i>descendant</i>)
</pre>
</td>
<td class="code">
<pre class="code yui">
.contains(<i>descendant</i>)
</pre>
</td>
<td class="notes"><p>Check to see if a node contains a certain descendant.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.show()
.hide()
</pre>
</td>
<td class="code">
<pre class="code yui">
.show()
.hide()
</pre>
</td>
<td class="notes">Make DOM nodes appear/disappear</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.fadeIn()
.fadeOut()
</pre>
</td>
<td class="code">
<pre class="code yui">
.show(<i>true</i>)
.hide(<i>true</i>)
</pre>
</td>
<td class="notes">
<p>In YUI, <code>.show()</code> and <code>.hide()</code> can be customized to use transitions supported by the <code>transition</code> module. These methods were added to YUI in 3.3.0.<p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
$.parseJSON( '{"name":"Douglas"}' )
</pre>
</td>
<td class="code">
<pre class="code yui">
Y.JSON.parse( '{"name":"Douglas"}' )
</pre>
</td>
<td class="notes"><p>Converts a JSON string into an object. Requires the <code>json-parse</code> module.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq"></pre>
</td>
<td class="code">
<pre class="code yui">
Y.JSON.stringify({name: "Douglas"})
</pre>
</td>
<td class="notes"><p>Converts an object to a JSON string. Requires the <code>json-stringify</code> module. No jQuery equivalent.</p></td></p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">$.proxy(<i>fn</i>, <i>context</i>)
</pre>
</td>
<td class="code">
<pre class="code yui">
Y.bind(<i>fn</i>, <i>context</i>)
</pre>
</td>
<td class="notes"><p>Creates a new function that will call the supplied function in a particular context.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.data(<i>key</i>)
.data(<i>key</i>, <i>value</i>)
</pre>
</td>
<td class="code">
<pre class="code yui">
.getData(<i>key</i>)
.setData(<i>key</i>, <i>value</i>)
</pre>
</td>
<td class="notes"><p>Stores data associated with a DOM element without modifying the DOM.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
.removeData()
.removeData(<i>key</i>)
</pre>
</td>
<td class="code">
<pre class="code yui">
.clearData()
.clearData(<i>key</i>)
</pre>
</td>
<td class="notes"><p>Removes the associated data.</p></td>
</tr>
</tbody>
</table>
<h2 id="events">Events</h2>
<table>
<thead>
<tr>
<th class="jq">jQuery 1.8.3</th>
<th class="yui">YUI 3.8.0</th>
<th class="notes">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td class="code">
<pre class="code jq">
$('#foo').click(<i>fn</i>)
$('#foo').focus(<i>fn</i>)
$('#foo').blur(<i>fn</i>)
$('#foo').mouseout(<i>fn</i>).mouseover(<i>fn</i>)
<i>// jQuery 1.4.2 and later allows you to
// register events when creating the element
</i>$('<p/>',{
text :<i>'foo'</i>,
className : <i>'bar'</i>,
click : <i>fn</i>,
focus : <i>fn</i>,
blur : <i>fn</i>
})
<i>//Alternatively, you can use the bind() method</i>
$('#foo').bind('click', <i>fn</i>);
</pre>
</td>
<td class="code">
<pre class="code yui">
Y.one('#foo').on('click', <i>fn</i>)
Y.one('#foo').on('focus', <i>fn</i>)
Y.one('#foo').on('blur', <i>fn</i>)
Y.one('#foo').on('mouseout', <i>fn</i>)
Y.one('#foo').on('mouseover', <i>fn</i>)
<i>// Alternatively, YUI allows you to attach multiple
// subscribers with a single call.</i>
Y.one('#foo').on({
click : <i>fn</i>,
focus : <i>fn</i>,
blur : <i>fn</i>,
mouseout : <i>fn</i>,
mouseover: <i>fn</i>
})
<i>// Or attach a single subscriber to multiple events.</i>
Y.one("#foo").on(['click', 'focus', 'blur'], <i>fn</i>)
</pre>
</td>
<td class="notes">
<p>In YUI, <code>.on()</code> is not chainable by default, but multiple subscribers can be attached in one call using the syntax shown here.</p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
$('#container').delegate('#target', 'click', <i>fn</i>);
</pre>
</td>
<td class="code">
<pre class="code yui">
Y.one('#container').delegate('click', <i>fn</i>, '#target');
</pre>
</td>
<td class="notes">
<p>Event listener will bind to #container and only fire the callback <i>fn</i> when a event's target is #target (or any other selector)</p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
$(document).on('click', '#target', <i>fn</i>);
</pre>
</td>
<td class="code">
<pre class="code yui">
Y.one(Y.config.doc).delegate('click', <i>fn</i>, '#target');
</pre>
</td>
<td class="notes">
<p>jQuery's delegate() is generally preferred over bind() because of performance as well as chaining limitations (<a href="http://www.alfajango.com/blog/the-difference-between-jquerys-bind-live-and-delegate/">source</a>).</p>
<p><code>.live()</code> was deprecated in jQuery 1.7, and removed in jQuery 1.9 in favour of <code>.on()</code>. As of jQuery 1.7, <code>.on()</code> is the actual method that bind(), live(), and delegate() passes through. (<a href="http://www.elijahmanor.com/differences-between-jquery-bind-vs-live-vs-delegate-vs-on/">source</a>)</p>
</td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
$('#foo').trigger('click');
</pre>
</td>
<td class="code">
<pre class="code yui">
Y.one('#foo').simulate('click');
</pre>
</td>
<td class="notes">
<p>Simulates a <em>click</em> event. In YUI, you'll need the <code>node-event-simulate</code> module.</p>
</td>
</tr>
</tbody>
</table>
<h2 id="selectors">Selectors</h2>
<table>
<thead>
<tr>
<th class="jq">jQuery 1.8.3</th>
<th class="yui">YUI 3.8.0</th>
<th class="notes">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<td class="code"><pre class="code jq">$('*')</pre></td>
<td class="code"><pre class="code yui">Y.all('*')</pre></td>
<td class="notes"><p>Select all nodes. Note that the default selector engine for YUI is CSS 2.1. For all examples in this section, use the <code>selector-css3</code> module for YUI.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':animated')</pre></td>
<td class="code"><pre class="code yui"></pre></td>
<td class="notes"><p>Psuedoclass to select all elements currently being animated. No YUI equivalent. </p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':button')</pre></td>
<td class="code"><pre class="code yui">Y.all('input[type=button], button')</pre></td>
<td class="notes"><p>Extension. In both jQuery and YUI you can run multiple selectors separated by commas.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':checkbox')</pre></td>
<td class="code"><pre class="code yui">Y.all('input[type=checkbox]')</pre></td>
<td class="notes"><p>Extension.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':checked')</pre></td>
<td class="code"><pre class="code yui">Y.all(':checked')</pre></td>
<td class="notes"><p>CSS3</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('parent > child')</pre></td>
<td class="code"><pre class="code yui">Y.all('parent > child')</pre></td>
<td class="notes"><p>Immediate child selector (child must be one level below parent)</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('parent child')</pre></td>
<td class="code"><pre class="code yui">Y.all('parent child')</pre></td>
<td class="notes"><p>Descendent selector (child can be at any level below parent)</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('div.class')</pre></td>
<td class="code"><pre class="code yui">Y.all('div.class')</pre></td>
<td class="notes"><p>Class selector</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(":contains('<i>foo</i>')")</pre></td>
<td class="code"><pre class="code yui">Y.all(':contains(<i>foo</i>)')</pre></td>
<td class="notes"><p>Extension to select all elements whose text matches 'foo'. jQuery can take quotes or not. YUI requires no quotes. The text matching is plain string comparison, not glob or regexp. Be careful with this one as it will return all matching ancestors, eg <code>[html, body, div]</code>.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
$(':disabled')
$(':enabled')
</pre></td>
<td class="code">
<pre class="code yui">
Y.all(':disabled')
Y.all(':enabled')
</pre>
</td>
<td class="notes"><p>CSS3. <code>'input[disabled]'</code> and <code>'input:not([disabled])'</code> also work in both libraries.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':empty')</pre></td>
<td class="code"><pre class="code yui">Y.all(':empty')</pre></td>
<td class="notes"><p>CSS3. Selects all elements that have no child nodes (excluding text nodes).</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':parent')</pre></td>
<td class="code"><pre class="code yui">Y.all(':not(:empty)')</pre></td>
<td class="notes"><p>Inverse of <code>:empty</code>. Will find all elements that are a parent of at least one element. jQuery's version is an extension. YUI's is CSS3.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('div:eq(<i>n</i>)')</pre></td>
<td class="code"><pre class="code yui">Y.all('div').item(<i>n</i>)</pre></td>
<td class="notes"><p>Extension. Selects <i>nth</i> element. YUI's <code>item()</code> will return <code>null</code> if there is no <code>nth</code> element. jQuery's selector will return an empty list <code>[]</code> on a match failure.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
$('div:even')
$('div:odd')
</pre>
</td>
<td class="code">
<pre class="code yui">
Y.all('div').even()
Y.all('div').odd()
</pre>
</td>
<td class="notes"><p>Extension. Selects all even or odd elements. Note that elements are 0-indexed and the 0th element is considered even. See also YUI's <code>NodeList.modulus(n, offset)</code>.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':file')</pre></td>
<td class="code"><pre class="code yui">Y.all('input[type=file]')</pre></td>
<td class="notes"><p>Extension. Find input elements whose type=file.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('div:first-child')</pre></td>
<td class="code"><pre class="code yui">Y.all('div:first-child')</pre></td>
<td class="notes"><p>CSS3. Selects the first child element of divs.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('div:first)</pre></td>
<td class="code"><pre class="code yui">Y.one('div')</pre></td>
<td class="notes"><p>The <code>.one()</code> method returns <code>null</code> if there is no match, and a single Node object if there is.</p></td>
</tr>
<tr>
<td class="code">
<pre class="code jq">
$('div:gt(<i>n</i>)');
$('div:lt(<i>n</i>)');
<i>// Or</i>
$('div').slice(<i>n + 1</i>);
$('div').slice(0,<i>n</i>);
</pre>
</td>
<td class="code">
<pre class="code yui">
Y.all('div').slice(<i>n + 1</i>);
Y.all('div').slice(0, <i>n</i>);
</pre>
</td>
<td class="notes"><p>Extension. <code>:gt</code> (greater than) selects all elements from index <code>n+1</code> onwards. <code>:lt</code> (less than) selects all nodes from 0 up to <code>n-1</code>.
</tr>
<tr>
<td class="code"><pre class="code jq">$('div:has(p)')</pre></td>
<td class="code">
<pre class="code yui">
var nodes = [];
Y.all('div').each(function (node) {
if (node.one('p')) {
nodes.push(node);
}
});
nodes = Y.all(nodes);
</pre>
</td>
<td class="notes"><p>Extension. Selects elements which contain at least one element that matches the specified selector. In this example, all <code>div</code> tags which have a <code>p</code> tag descendent will be selected.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':header')</pre></td>
<td class="code"><pre class="code yui">Y.all('h1,h2,h3,h4,h5,h6')</pre></td>
<td class="notes"><p>Extension. Selects all heading elements. Rarely used.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('div:hidden')</pre></td>
<td class="code">
<pre class="code yui">
var hidden = [];
Y.all('div').each(function(node) {
if ((node.get('offsetWidth') === 0 &&
node.get('offsetHeight') === 0) ||
node.get('display') === 'none') {
hidden.push(node);
}
});
hidden = Y.all(hidden);
</pre>
</td>
<td class="notes">
<p>Extension. In jQuery > 1.3.2 <code>:hidden</code> selects all elements (or descendents of elements) which <a href="http://docs.jquery.com/Release:jQuery_1.3.2#:visible.2F:hidden_Overhauled">take up no visual space</a>. Elements with <code>display:none</code> or whose <code>offsetWidth/offsetHeight</code> equal 0 are considered hidden. Elements with <code>visibility:hidden</code> are not considered hidden.</p>
<p>The YUI equivalent would essentially be a port of the jQuery code that implements <code>:hidden</code>. This might be a good candidate for a patch to YUI.</p>
</td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('#id')</pre></td>
<td class="code"><pre class="code yui">Y.all('#id')</pre></td>
<td class="notes"><p>CSS3. Identity selector.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('input:image')</pre></td>
<td class="code"><pre class="code yui">Y.all('input[type=image]')</pre></td>
<td class="notes"><p>Extension. Selects all inputs of type image.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':input')</pre></td>
<td class="code"><pre class="code yui">Y.all('input,textarea,select,button')</pre></td>
<td class="notes"><p>Extension. Selects all user-editable form elements.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$(':last-child')</pre></td>
<td class="code"><pre class="code yui">Y.all(':last-child')</pre></td>
<td class="notes"><p>CSS3.</p></td>
</tr>
<tr>
<td class="code"><pre class="code jq">$('div:last')</pre></td>
<td class="code">
<pre class="code yui">
var list = Y.all('div'),
len = list.size(),
last;
if (len) {
last = list.item(len - 1);
}
</pre>
</td>
<td class="notes">Extension. Selects the last element matched by the selector.</td>
</tr>
<tr>