Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Cancel OnMouseOver Event on nested divs

onmouse event on nested divs



6:39 pm on Aug 22, 2008 (gmt 0)

5+ Year Member

Hello everyone,
I have a container div that has an onmouseout event that basically shrinks it's size, and within this div, I have two block level elements, a nested div and an image. What's happening is while the mouse is still within the container div, and mouseover's either the nested div or the image, it triggers the onmouseout event on the container event.

For an example, see <snip>

How can I cancel the onmouseout event when it goes into the nested block elements, but keep it active for when the mouse actually leaves the outside edge of the container div?

Reps to the first fix!


[edited by: DrDoc at 9:20 pm (utc) on Aug. 23, 2008]
[edit reason] No URIs, please. See posting guidelines. [/edit]


3:30 am on Aug 25, 2008 (gmt 0)

5+ Year Member

I would make a global variable in javascript called 'currentContainer' - update this everytime you enter/leave a div. Then code the onmouseoutevent to look and see if the currentContainer is really just a div within the container - if so then don't do anything.


2:16 pm on Aug 25, 2008 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Perhaps you could use setTimeout and cancelTimeout.

Instead of shrinking the size onmouseout, call setTimeout to shrink the size after some small amount of time (maybe 300ms). Then, add an onmouseover listener that will call cancelTimeout to prevent the method for shrinking the size from being called. Therefore, if you are mousing over any of the nested items, the call to shrink the size will always be cancelled before it can call that method.


7:20 pm on Aug 25, 2008 (gmt 0)

5+ Year Member

thanks for the reply, your response worked the best.

I set the onmouseout event on the container div to:


and on the nested div,


Worked like a charm! Thank you, I wasn't aware of a clearTimeout function.

Thanks everyone!


7:21 pm on Aug 25, 2008 (gmt 0)

5+ Year Member

csuguy, thanks for your reply as well, unfortunately, the onmouseout fires before the mouseover, so I couldn't update any global variables before the onmouseout fired. I tried it with a setTimeout, but it got messy.


9:23 pm on Aug 25, 2008 (gmt 0)

5+ Year Member

Ah well - glad you got it working!



Featured Threads

Hot Threads This Week

Hot Threads This Month