]> source.dussan.org Git - jquery.git/commitdiff
Event: Only check elements for delegation matches 2566/head 2567/head
authorRichard Gibson <richard.gibson@gmail.com>
Wed, 16 Jan 2013 05:14:57 +0000 (00:14 -0500)
committerRichard Gibson <richard.gibson@gmail.com>
Mon, 10 Aug 2015 14:26:13 +0000 (10:26 -0400)
Closes gh-2529
Ref trac-13208
(cherry picked from commit fc2ba2e1361126c39f955437ee025cfca3bffa65)

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

index f0604503c2194cb1fddde6d665f413e02b5298b7..156bc016a8c2f971dce1ccb1f389f221e4d020c6 100644 (file)
@@ -483,8 +483,9 @@ jQuery.event = {
 
                        for ( ; cur !== this; cur = cur.parentNode || this ) {
 
+                               // Don't check non-elements (#13208)
                                // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
-                               if ( cur.disabled !== true || event.type !== "click" ) {
+                               if ( cur.nodeType === 1 && (cur.disabled !== true || event.type !== "click") ) {
                                        matches = [];
                                        for ( i = 0; i < delegateCount; i++ ) {
                                                handleObj = handlers[ i ];
index 2e86eb78d6dbcde34eb2a83f3388dbbb21005f34..c53690abb286d1a2693c89e2ab9647a8da5c5578 100644 (file)
@@ -1834,6 +1834,17 @@ test( "delegated event with selector matching Object.prototype property (#13203)
        equal( matched, 0, "Nothing matched 'toString'" );
 });
 
+test( "delegated event with intermediate DOM manipulation (#13208)", function() {
+       expect(1);
+
+       jQuery("#foo").on( "click", "[id=sap]", function() {});
+       jQuery("#sap").on( "click", "[id=anchor2]", function() {
+               document.createDocumentFragment().appendChild( this.parentNode );
+               ok( true, "Element removed" );
+       });
+       jQuery("#anchor2").trigger("click");
+});
+
 test("stopPropagation() stops directly-bound events on delegated target", function() {
        expect(1);