PDA

View Full Version : Cascading events help


ScottInTexas
05-04-2003, 06:42 PM
I want to use the mouseOut event on the div and on the cells in the table in the div. The problem is that the mouseOut event firing for the cell cascades up and fires for the div as well. Is there a way to stop this?

brothercake
05-04-2003, 07:10 PM
Yes there is - check out http://www.codingforums.com/showthread.php?s=&threadid=16823

Use the contains() method to work out where the event is coming from; contains is proprietary to win/ie but also works in Opera 7.

jkd's prototype will make it work in mozilla as well:

HTMLElement.prototype.contains = function(node) {
if (node == null)
return false;
if (node == this)
return true;
else
return this.contains(node.parentNode);
}

However if you want full support (so including mac/ie5 and safari/konqueror, neither of which support HTMLElement prototyping) then you'll need to define it as a method of the DIV object itself:

myDivObj.contains = function( ... etc


I used this very thing quite recently for a menu script - http://www.brothercake.com/scripts/listmenu/