Skip to content

Commit 9d820fb

Browse files
committed
Event: Only check elements for delegation matches
Closes gh-2529 Ref trac-13208 (cherry picked from commit fc2ba2e)
1 parent 9adfad1 commit 9d820fb

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
@@ -483,8 +483,9 @@ jQuery.event = {
483483

484484
for ( ; cur !== this; cur = cur.parentNode || this ) {
485485

486+
// Don't check non-elements (#13208)
486487
// Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
487-
if ( cur.disabled !== true || event.type !== "click" ) {
488+
if ( cur.nodeType === 1 && (cur.disabled !== true || event.type !== "click") ) {
488489
matches = [];
489490
for ( i = 0; i < delegateCount; i++ ) {
490491
handleObj = handlers[ i ];

test/unit/event.js

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

1837+
test( "delegated event with intermediate DOM manipulation (#13208)", function() {
1838+
expect(1);
1839+
1840+
jQuery("#foo").on( "click", "[id=sap]", function() {});
1841+
jQuery("#sap").on( "click", "[id=anchor2]", function() {
1842+
document.createDocumentFragment().appendChild( this.parentNode );
1843+
ok( true, "Element removed" );
1844+
});
1845+
jQuery("#anchor2").trigger("click");
1846+
});
1847+
18371848
test("stopPropagation() stops directly-bound events on delegated target", function() {
18381849
expect(1);
18391850

0 commit comments

Comments
 (0)