I was just reading over on Jon Hartmann's blog about leveraging event bubbling in jQuery. It's a very cool concept and one that I have not played around with enough so far. When I was reading his post, however, I immediately wondered if default actions could be prevented using this technique. For example, if I have links within a list and the click handler is on the list (UL), can I prevent the default action of the link (navigate away from page) once the event has bubbled up beyond the link? Or, is it too late at that point? To test this, I put together a little demo in which the ancestor element, the UL, prevents the default on all actions:
As you can see from the video, even though the UL is handling an event that has bubbled past the link (target element), it is still able to prevent the default action of the link navigation. I'm sure if I had a richer understanding of the browser's event model, this would be obvious; but, I'm still learning. If I had to extrapolate this out into a meaning, it seems that you have the ability to control an event outcome until the browser has stopped handling it at every different level of listening.
Here is the code that I executed in the demo:
I am not sure that I know what kind of situation this is best suited for; but, I think it's worth playing around with some.
Want to use code from this post? Check out the license.