Fix #13208: only check elements for delegation matches

This commit is contained in:
Richard Gibson 2013-01-16 00:14:57 -05:00
parent 65df32dc21
commit fc2ba2e136
2 changed files with 13 additions and 1 deletions

View 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 ];

View 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);