aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2011-10-21 10:56:16 -0400
committerDave Methvin <dave.methvin@gmail.com>2011-10-24 11:18:13 -0400
commit9fabe2028f05bc409f937ff7cd71caaacd26f945 (patch)
tree1b186bd01dadf4c60f69126a87cb31fb1bb72084
parentc4cc343c9cc47dbb1aa3501a9098e29aac74ad67 (diff)
downloadjquery-9fabe2028f05bc409f937ff7cd71caaacd26f945.tar.gz
jquery-9fabe2028f05bc409f937ff7cd71caaacd26f945.zip
Don't run direct handlers if delegate did .stopPropagation().
-rw-r--r--src/event.js2
-rw-r--r--test/unit/event.js16
2 files changed, 17 insertions, 1 deletions
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( '<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);