@@ -310,8 +310,10 @@ test("bind/one/unbind(Object)", function(){
310
310
test ( "on/off(Object), delegate/undelegate(String, Object)" , function ( ) {
311
311
expect ( 6 ) ;
312
312
313
- var clickCounter = 0 , mouseoverCounter = 0 ,
314
- $p = jQuery ( "#firstp" ) , $a = $p . find ( "a:first" ) ;
313
+ var clickCounter = 0 ,
314
+ mouseoverCounter = 0 ,
315
+ $p = jQuery ( "#firstp" ) ,
316
+ $a = $p . find ( "a" ) . eq ( 0 ) ;
315
317
316
318
var events = {
317
319
"click" : function ( event ) {
@@ -326,7 +328,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() {
326
328
$a . trigger ( "click" ) . trigger ( "mouseover" ) ;
327
329
}
328
330
329
- jQuery ( document ) . on ( events , "#firstp a:first " ) ;
331
+ jQuery ( document ) . on ( events , "#firstp a" ) ;
330
332
$p . delegate ( "a" , events , 2 ) ;
331
333
332
334
trigger ( ) ;
@@ -339,7 +341,7 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() {
339
341
equal ( clickCounter , 4 , "undelegate" ) ;
340
342
equal ( mouseoverCounter , 4 , "undelegate" ) ;
341
343
342
- jQuery ( document ) . off ( events , "#firstp a:first " ) ;
344
+ jQuery ( document ) . off ( events , "#firstp a" ) ;
343
345
344
346
trigger ( ) ;
345
347
equal ( clickCounter , 4 , "off" ) ;
@@ -349,19 +351,21 @@ test("on/off(Object), delegate/undelegate(String, Object)", function() {
349
351
test ( "on/delegate immediate propagation" , function ( ) {
350
352
expect ( 2 ) ;
351
353
352
- var $p = jQuery ( "#firstp" ) , $a = $p . find ( "a:first" ) , lastClick ;
354
+ var lastClick ,
355
+ $p = jQuery ( "#firstp" ) ,
356
+ $a = $p . find ( "a" ) . eq ( 0 ) ;
353
357
354
358
lastClick = "" ;
355
- jQuery ( document ) . on ( "click" , "#firstp a:first " , function ( e ) {
359
+ jQuery ( document ) . on ( "click" , "#firstp a" , function ( e ) {
356
360
lastClick = "click1" ;
357
361
e . stopImmediatePropagation ( ) ;
358
362
} ) ;
359
- jQuery ( document ) . on ( "click" , "#firstp a:first " , function ( e ) {
363
+ jQuery ( document ) . on ( "click" , "#firstp a" , function ( e ) {
360
364
lastClick = "click2" ;
361
365
} ) ;
362
366
$a . trigger ( "click" ) ;
363
367
equal ( lastClick , "click1" , "on stopImmediatePropagation" ) ;
364
- jQuery ( document ) . off ( "click" , "#firstp a:first " ) ;
368
+ jQuery ( document ) . off ( "click" , "#firstp a" ) ;
365
369
366
370
lastClick = "" ;
367
371
$p . delegate ( "a" , "click" , function ( e ) {
@@ -490,7 +494,7 @@ test("bind(), namespaced events, cloned events", 18, function() {
490
494
491
495
// Make sure events stick with appendTo'd elements (which are cloned) #2027
492
496
jQuery ( "<a href='#fail' class='test'>test</a>" ) . on ( "click" , function ( ) { return false ; } ) . appendTo ( "#qunit-fixture" ) ;
493
- ok ( jQuery ( "a.test:first" ) . triggerHandler ( "click" ) === false , "Handler is bound to appendTo'd elements" ) ;
497
+ ok ( jQuery ( "a.test" ) . eq ( 0 ) . triggerHandler ( "click" ) === false , "Handler is bound to appendTo'd elements" ) ;
494
498
} ) ;
495
499
496
500
test ( "bind(), multi-namespaced events" , function ( ) {
@@ -996,7 +1000,7 @@ test("trigger(type, [data], [fn])", function() {
996
1000
997
1001
var pass = true , elem2 ;
998
1002
try {
999
- elem2 = jQuery ( "#form input:first" ) ;
1003
+ elem2 = jQuery ( "#form input" ) . eq ( 0 ) ;
1000
1004
elem2 . get ( 0 ) . style . display = "none" ;
1001
1005
elem2 . trigger ( "focus" ) ;
1002
1006
} catch ( e ) {
@@ -1006,7 +1010,7 @@ test("trigger(type, [data], [fn])", function() {
1006
1010
1007
1011
pass = true ;
1008
1012
try {
1009
- jQuery ( "#qunit-fixture table:first" ) . bind ( "test:test" , function ( ) { } ) . trigger ( "test:test" ) ;
1013
+ jQuery ( "#qunit-fixture table" ) . eq ( 0 ) . bind ( "test:test" , function ( ) { } ) . trigger ( "test:test" ) ;
1010
1014
} catch ( e ) {
1011
1015
pass = false ;
1012
1016
}
@@ -1717,10 +1721,24 @@ test("jQuery.off using dispatched jQuery.Event", function() {
1717
1721
1718
1722
test ( "delegated event with delegateTarget-relative selector" , function ( ) {
1719
1723
expect ( 3 ) ;
1720
- var markup = jQuery ( "<ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul>" ) . appendTo ( "#qunit-fixture" ) ;
1724
+ var markup = jQuery ( "<div><ul><li><a id=\"a0\"></a><ul id=\"ul0\"><li class=test><a id=\"a0_0\"></a></li><li><a id=\"a0_1\"></a></li></ul></li></ul></div>" ) . appendTo ( "#qunit-fixture" ) ;
1725
+
1726
+ // Non-positional selector (#12383)
1727
+ markup . find ( "#ul0" )
1728
+ . on ( "click" , "div li a" , function ( ) {
1729
+ ok ( false , "div is ABOVE the delegation point!" ) ;
1730
+ } )
1731
+ . on ( "click" , "ul a" , function ( ) {
1732
+ ok ( false , "ul IS the delegation point!" ) ;
1733
+ } )
1734
+ . on ( "click" , "li.test a" , function ( ) {
1735
+ ok ( true , "li.test is below the delegation point." ) ;
1736
+ } )
1737
+ . find ( "#a0_0" ) . trigger ( "click" ) . end ( )
1738
+ . off ( "click" ) ;
1721
1739
1722
1740
// Positional selector (#11315)
1723
- markup
1741
+ markup . find ( "ul" ) . eq ( 0 )
1724
1742
. on ( "click" , ">li>a" , function ( ) {
1725
1743
ok ( this . id === "a0" , "child li was clicked" ) ;
1726
1744
} )
@@ -1732,21 +1750,6 @@ test( "delegated event with delegateTarget-relative selector", function() {
1732
1750
. find ( "a" ) . trigger ( "click" ) . end ( )
1733
1751
. find ( "#ul0" ) . off ( ) ;
1734
1752
1735
- // Non-positional selector (#12383)
1736
- markup = markup . wrap ( "<div />" ) . parent ( ) ;
1737
- markup
1738
- . find ( "#ul0" )
1739
- . on ( "click" , "div li a" , function ( ) {
1740
- ok ( false , "div is ABOVE the delegation point!" ) ;
1741
- } )
1742
- . on ( "click" , "ul a" , function ( ) {
1743
- ok ( false , "ul is the delegation point!" ) ;
1744
- } )
1745
- . on ( "click" , "li.test a" , function ( ) {
1746
- ok ( true , "li.test is below the delegation point." ) ;
1747
- } )
1748
- . find ( "#a0_0" ) . trigger ( "click" ) ;
1749
-
1750
1753
markup . remove ( ) ;
1751
1754
} ) ;
1752
1755
@@ -2558,12 +2561,12 @@ test( "make sure events cloned correctly", 18, function() {
2558
2561
2559
2562
clone = fixture . clone ( true ) ;
2560
2563
2561
- clone . find ( "p:first" ) . trigger ( "click" , true ) ; // 3 events should fire
2564
+ clone . find ( "p" ) . eq ( 0 ) . trigger ( "click" , true ) ; // 3 events should fire
2562
2565
clone . find ( "#check1" ) . trigger ( "change" , true ) ; // 3 events should fire
2563
2566
clone . remove ( ) ;
2564
2567
2565
2568
clone = fixture . clone ( true , true ) ;
2566
- clone . find ( "p:first" ) . trigger ( "click" , true ) ; // 3 events should fire
2569
+ clone . find ( "p" ) . eq ( 0 ) . trigger ( "click" , true ) ; // 3 events should fire
2567
2570
clone . find ( "#check1" ) . trigger ( "change" , true ) ; // 3 events should fire
2568
2571
2569
2572
fixture . off ( ) ;
@@ -2573,11 +2576,11 @@ test( "make sure events cloned correctly", 18, function() {
2573
2576
p . trigger ( "click" ) ; // 0 should be fired
2574
2577
checkbox . trigger ( "change" ) ; // 0 should be fired
2575
2578
2576
- clone . find ( "p:first" ) . trigger ( "click" , true ) ; // 3 events should fire
2579
+ clone . find ( "p" ) . eq ( 0 ) . trigger ( "click" , true ) ; // 3 events should fire
2577
2580
clone . find ( "#check1" ) . trigger ( "change" , true ) ; // 3 events should fire
2578
2581
clone . remove ( ) ;
2579
2582
2580
- clone . find ( "p:first" ) . trigger ( "click" ) ; // 0 should be fired
2583
+ clone . find ( "p" ) . eq ( 0 ) . trigger ( "click" ) ; // 0 should be fired
2581
2584
clone . find ( "#check1" ) . trigger ( "change" ) ; // 0 events should fire
2582
2585
} ) ;
2583
2586
0 commit comments