Alex Rivera | Logout

jQuery event bubbling

Asked 2011-08-04T17:26:15.413
21

I want to understand how exactly to interpret bubbling. Does it mean going up the HTML code hierarchy or something else?

Secondly, I was going through an example and I could not understand the last part where it says

The P-based click handler listens for the click event and then prevents it from being propagated (bubbling up)

What does this mean?

Edit
Report

3 Answers

12
return false;

will prevent "bubbling". It's used to stop default actions like checking a checkbox, opening a select, a click, etc.

To stop further handlers from executing after one bound using .live(), the handler must return false. Calling .stopPropagation() will not accomplish this.

From Caveats in jQuery .live()


Reasoning (thanks to @AlienWebguy):

The reason stopPropagation() doesn't work with live() is that live() binds the event to document so by the time it fires there's no where else for it to propagate.

answered 2011-08-04T17:28:47.927
0

Also:

event.stopPropagation()

http://api.jquery.com/event.stopPropagation/

answered 2011-08-04T17:29:55.723
0

Yes, the event goes up the tree and if any element has a handler for that event it will be called. By adding return:false in a handler of one of the elements the event will be prevented from bubbling.

answered 2011-08-04T17:31:58.313

Your Answer