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 trial

JavaScript

why we may use STOPPROPAGATION() to prevent .bubbling

why se may use the javascript method STOPPROPAGATION() to prevent bubbling in the DOM as we can simply don't use bubbling?

1 Answer

Steven Parker
Steven Parker
243,656 Points

Propagation ("bubbling") is very handy, and essential for delegated handlers. But there are times when you catch an event at some element and because of the way you are handling it, you don't want any handlers attached to parent elements to also fire.

So the reason you would use this would depend on the way you have attached handlers, and what the handler code is doing.