Permalink
Browse files

Event: Only check elements for delegation matches

Closes gh-2529
Ref trac-13208
(cherry picked from commit fc2ba2e)
  • Loading branch information...
gibson042 committed Jan 16, 2013
1 parent 9adfad1 commit 9d820fbde6d89bc7a06e2704be61cf6c0b4d6e3c
Showing with 13 additions and 1 deletion.
  1. +2 −1 src/event.js
  2. +11 −0 test/unit/event.js
View
@@ -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 ];
View
@@ -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);

0 comments on commit 9d820fb

Please sign in to comment.