Resources‎ > ‎Tips and Tricks‎ > ‎Javascript‎ > ‎Events‎ > ‎

Prevent events from bubbling up

If you have nested objects that each have their own onclick function defined, each event will fire.  

Say you have a table, with x TR rows, and y TD cells, and each has an onclick.  Clicking on a cell will fire the onclick for TD, for TR and for the TABLE.  

To prevent this, add the following to your event or function.  This will basically empty the event queue.

event.cancelBubble = true;
Comments