views:

381

answers:

1

How do I check if the mouse pointer is in/on another div/id/a?

^a href="#" onmouseover="showmenu('top_3_menu_1_1')">Option One

function showmenu(elmnt) { document.getElementById(elmnt).style.visibility="visible"; }

function hidemenu(elmnt) { if mouse pointer is not in location A or B do something }

+1  A: 

A little bit down on this blog (scroll down) there is an implementation of how to implement MouseEnter/MouseLeave cross browser. Without this then due to "event bubbling" you will get false positives on MouseOver/Out which means that your trapping of mouseover/out will fail...!

If you implement the above check however in MouseOver/Out you will have a perfect valid starting point for setting some sort of flag in event handlers which makes it possible for you to at an arbitrage time check those flags to see if mouse is "over or out" of specific DOM element...

Also your "menu hiding/showing" will mostly work with the above check, however if all you want to do is show and hide there exists perfectly valid pure CSS solutions for that ;)

(Google for them)

Thomas Hansen