Skip to content

Commit fc2ba2e

Browse files
committed
Fix #13208: only check elements for delegation matches
1 parent 65df32d commit fc2ba2e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/event.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,9 @@ jQuery.event = {
410410

411411
for ( ; cur != this; cur = cur.parentNode || this ) {
412412

413+
// Don't check non-elements (#13208)
413414
// Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
414-
if ( cur.disabled !== true || event.type !== "click" ) {
415+
if ( cur.nodeType === 1 && (cur.disabled !== true || event.type !== "click") ) {
415416
matches = [];
416417
for ( i = 0; i < delegateCount; i++ ) {
417418
handleObj = handlers[ i ];

test/unit/event.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,17 @@ test( "delegated event with selector matching Object.prototype property (#13203)
18111811
equal( matched, 0, "Nothing matched 'toString'" );
18121812
});
18131813

1814+
test( "delegated event with intermediate DOM manipulation (#13208)", function() {
1815+
expect(1);
1816+
1817+
jQuery("#foo").on( "click", "#sap", function() {});
1818+
jQuery("#sap").on( "click", "#anchor2", function() {
1819+
jQuery( this.parentNode ).remove();
1820+
ok( true, "Element removed" );
1821+
});
1822+
jQuery("#anchor2").trigger("click");
1823+
});
1824+
18141825
test("stopPropagation() stops directly-bound events on delegated target", function() {
18151826
expect(1);
18161827

0 commit comments

Comments
 (0)