Preventing event bubble propagation in Javascript
This post is basically a bunch of tests on the information provided on chapter 9 of the book Professional Javascript for Web Developers.
I’ve been working with some javascript events behaviour and I needed to explore the Event Bubbling model in a variety of browsers. I created a simple test page for testing how js events bubble. I added a simple on click event to the different elements on a page and associated it with a function that simply alerts the name of the element. This is very usefull to see how events propagate. Go test them and see for yourself.
Results on Windows XP
| Â | IE 6.0.2900 | Firefox 1.5.07 | Opera 9.0.1 |
|---|---|---|---|
| Clicking outside the Body | Document | Document - Window | Window - Document |
| Clicking Inside the Body | Body - Document | Body - Document - Window | Body - Window - Document |
| Clicking Inside the Element | Element - Body - Document | Element - Body - Document - Window | Element - Body - Window - Document |
Now this works pretty fine and is very straightforward. But if you want to prevent an event fired by an element to bubble all the way up the bubble chain, the code is the following:
function al_p(e) { alert('Element'); if((navigator.userAgent.indexOf("MSIE")>-1 && navigator.userAgent.indexOf("compatible")>1 && !(navigator.userAgent.indexOf("opera")>-1))) { //IE
if(!e) e = window.event; e.cancelBubble = true;
} else {
//Other Browsers
e.stopPropagation(); } };
You can test the results here: Javascript Event Bubbling Prevention Test



Hi.
Nice forum design. Okay, I need your help.
So, I wanna make my little sister’s site, and I am looking for site template.
Can you advice some online place or other resource where I can find many site templates?
It would be better if it will be free:)
I think many of us have personal sites, do you design it yourself?
Thanks, Bill.
January 8th, 2007 at 1:53 am
Hi Bill, this is a blog running wordpress, an open source (and free) blogging application, you can download it at the Wordpress site, If you don´t have a server you can use their own hosted solution here. Now regarding the template, I designed it myself.. but there are plenty of free wordpress templates out there, just google “wordpress theme”. The Wordpress themes repository is also a good place to start.
Hope this helps you, Emiliano.
January 8th, 2007 at 2:38 pm
Hi.
Good design, who make it?
November 28th, 2007 at 1:12 pm
??? ??????????? ? ????? ????? getup.com.ua
September 23rd, 2010 at 7:38 am