Skip to content

Commit

Permalink
Don't run direct handlers if delegate did .stopPropagation().
Browse files Browse the repository at this point in the history
  • Loading branch information
dmethvin committed Oct 24, 2011
1 parent c4cc343 commit 9fabe20
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/event.js
Expand Up @@ -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 );
}

Expand Down
16 changes: 16 additions & 0 deletions test/unit/event.js
Expand Up @@ -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( '<div><p><a href="#">target</a></p></div>' );
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);

Expand Down

0 comments on commit 9fabe20

Please sign in to comment.