Skip to main content

Bug Tracker

Side navigation

#1948 closed bug (invalid)

Opened November 20, 2007 02:00PM UTC

Closed November 20, 2007 04:02PM UTC

Last modified March 21, 2011 08:17PM UTC

handle(): Stop event bubbling for other jQuery handlers?

Reported by: olau Owned by:
Priority: major Milestone: 1.2.2
Component: event Version: 1.2.1
Keywords: Cc:
Blocked by: Blocking:
Description

Shouldn't "return false;" in an event handler prevent other jQuery handlers from running? That's how I understand the docs.

Currently, code like this

$(".ensureLoggedIn").click(function (event) {

console.log("test1");

return false;

}).click(function() {

console.log("test2");

});

prints "test1" followed by "test2". Which is not surprising given that handle() in jQuery calls preventDefault and stopPropagation but doesn't stop the handler invocation loop. If you add "break;" after the call to stopPropagation in handle(), I only get "test1" and not "test2".

Attachments (0)
Change History (4)

Changed November 20, 2007 04:02PM UTC by brandon comment:1

resolution: → invalid
status: newclosed

It stops the event from bubbling to a parent. It does not prevent other handlers from running on the same element. This is in accordance with the standards. It should also be noted that there is no guarantee to the order in which the handlers are invoked.

Changed November 20, 2007 05:00PM UTC by olau comment:2

Okay, sorry for the inconvenience. Thanks.

Changed November 23, 2007 06:29PM UTC by olau comment:3

FWIW, I've clarified the docs a bit (http://docs.jquery.com/Events_%28Guide%29 and http://docs.jquery.com/Events/bind) for those of us who don't know the standards as well as others. :-)

Changed March 21, 2011 08:17PM UTC by cr125rider comment:4

This write up helped me, thank you for taking the time to post a resolution to the problem.