Ticket #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: | ||
| Blocking: | Blocked by: |
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
comment:1 Changed 5 years ago by brandon
- Status changed from new to closed
- Resolution set to invalid
comment:3 Changed 5 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. :-)
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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.