Bug Tracker

Modify

Ticket #1948 (closed bug: invalid)

Opened 5 years ago

Last modified 2 years ago

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

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 5 years ago by olau

Okay, sorry for the inconvenience. Thanks.

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

comment:4 Changed 2 years ago by cr125rider

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.