]> source.dussan.org Git - jquery.git/commitdiff
Fix #11315. Selector for .on() is relative to delegateTarget.
authorDave Methvin <dave.methvin@gmail.com>
Wed, 27 Jun 2012 00:36:00 +0000 (20:36 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Wed, 27 Jun 2012 15:54:04 +0000 (11:54 -0400)
This fixes a regresssion from 1.6.4. Be aware that nearly every place that this bug comes into play, the selector in use is incredibly inefficient.

src/event.js
test/unit/event.js

index 33610fd6f32e5796e7871235c4bfc8d943b85024..8e17273f97a5964b1ccc3b2c84fbbc190b02c111 100644 (file)
@@ -384,7 +384,7 @@ jQuery.event = {
 
                        // Pregenerate a single jQuery object for reuse with .is()
                        jqcur = jQuery(this);
-                       jqcur.context = this.ownerDocument || this;
+                       jqcur.context = this;
 
                        for ( cur = event.target; cur != this; cur = cur.parentNode || this ) {
 
index a6ee455fbdb45cc1e87cca3dd41abd1553b3f0af..07da83260531bb341de3bb5e66c6b34db826d390 100644 (file)
@@ -2333,6 +2333,20 @@ test("jQuery.off using dispatched jQuery.Event", function() {
                .remove();
 });
 
+test( "delegated event with delegateTarget-relative selector (#)", function() {
+       expect(1);
+       var markup = jQuery( '<ul><li><ul id="u1"><li id="f1"></li></ul></li>' ).appendTo("body");
+       
+       markup
+               .find("#u1")
+                       .on( "click", "li:first", function() {
+                               ok( this.id === "f1" , "first li under #u1 was clicked" );
+                       })
+                       .find("#f1").click().end()
+               .end()
+               .remove();
+});
+
 test("stopPropagation() stops directly-bound events on delegated target", function() {
        expect(1);