homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Cancel OnMouseOver Event on nested divs
onmouse event on nested divs

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

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)

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)

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)

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)

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)

Ah well - glad you got it working!


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved