From: Dave Methvin Date: Fri, 21 Oct 2011 14:56:16 +0000 (-0400) Subject: Don't run direct handlers if delegate did .stopPropagation(). X-Git-Tag: 1.7rc1~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9fabe2028f05bc409f937ff7cd71caaacd26f945;p=jquery.git Don't run direct handlers if delegate did .stopPropagation(). --- diff --git a/src/event.js b/src/event.js index 5d4d9a23b..38fd82b5e 100644 --- a/src/event.js +++ b/src/event.js @@ -459,7 +459,7 @@ jQuery.event = { delete event.delegateTarget; // Run non-delegated handlers for this level - if ( handlers.length ) { + if ( handlers.length && !event.isPropagationStopped() ) { dispatch( this, event, handlers, args ); } diff --git a/test/unit/event.js b/test/unit/event.js index 28df8ee39..cce9061ed 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2054,6 +2054,22 @@ test(".delegate()/.undelegate()", function() { jQuery("#body").undelegate("#nothiddendiv div", "click"); }); +test("stopPropagation() stops directly-bound events on delegated target", function() { + expect(1); + + var markup = jQuery( '

target

' ); + markup + .on( "click", function() { + ok( false, "directly-bound event on delegate target was called" ); + }) + .on( "click", "a", function( e ) { + e.stopPropagation(); + ok( true, "delegated handler was called" ); + }) + .find("a").click().end() + .remove(); +}); + test("undelegate all bound events", function(){ expect(1);