Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 9 years ago

#1948 closed bug (invalid)

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".

Change History (4)

comment:1 Changed 13 years ago by brandon

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.

comment:2 Changed 13 years ago by olau

Okay, sorry for the inconvenience. Thanks.

comment:3 Changed 13 years ago by olau

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. :-)

comment:4 Changed 9 years ago by cr125rider

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

Note: See TracTickets for help on using tickets.