]> source.dussan.org Git - jquery.git/commitdiff
Fix #13208: only check elements for delegation matches
authorRichard Gibson <richard.gibson@gmail.com>
Wed, 16 Jan 2013 05:14:57 +0000 (00:14 -0500)
committerRichard Gibson <richard.gibson@gmail.com>
Wed, 16 Jan 2013 05:14:57 +0000 (00:14 -0500)
src/event.js
test/unit/event.js

index 772d65ef49533da78999f38cab4e05af9b55b092..6554769ba09fb389fc12833fe8dca2691ac597ee 100644 (file)
@@ -410,8 +410,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 6984b4945b6037ee0a2c653263fbf6072fda20da..bde9f7f4315295255e0d6a45660c9274f810c1cb 100644 (file)
@@ -1811,6 +1811,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", "#sap", function() {});
+       jQuery("#sap").on( "click", "#anchor2", function() {
+               jQuery( this.parentNode ).remove();
+               ok( true, "Element removed" );
+       });
+       jQuery("#anchor2").trigger("click");
+});
+
 test("stopPropagation() stops directly-bound events on delegated target", function() {
        expect(1);