Cancel Event-Bubbling in Dojo
Monday, September 28th, 2009
If you have ever worked with a set of nested div’s which needed to listen for onclick event you must surely have encountered this issue.
If child div is clicked the parent’s click event will also be triggered because of Event-Bubbling.
The Internet Explorer 4 or later and Netscape 6 event model mechanism that propagates events from the target element upward through the HTML Page.
Me and my team mate Anoop were struggling with the problem for a long time and today he finally found a solution to it.
Use the code below to cancel the Event-Bubbling.
dojo.connect(dojo.byId("myDiv"),"onmouseover",
function(evt){
//Do Something
//..
//..
evt.stopPropagation(); //Stop Event Bubbling
});
Here passing the evt paramenter is very crucial otherwise the Event Bubbling wont stop!
