Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoseph Frazer
5,404 PointsI am super confused with event bubbling... any help?
With event bubbling I am confused with what it is and how to get rid of it or whatever.
1 Answer
Steven Parker
231,248 PointsEvent bubbling is simply triggering events up the DOM tree in reverse nesting order.
For example. let's consider a mouse click on a button:
- The button becomes the "event target"
- If a click event handler is set for that object, the event is triggered
- If the handler does not stop propagation (bubbling), the event "bubbles up" to the parent object.
- If the current (parent) object is not the document itself, go back and repeat from step 2
As mentioned in step 3, you can stop bubbling by calling "stopPropagation()
" on the event object in the handler code.
I found this one-page event tuturial that includes some nice graphics and demos that may also help make the process clearer.