views:

450

answers:

2

I could write something pretty easily to determine whether the mouse is over a given element, but is there already anything in the jQuery core library (or a plugin I guess) that will tell me whether the current mouse position is over a given element?

+2  A: 

No.

You can use jQuery's hover event to keep track manually:

$(...).hover(
    function() { $.data(this, 'hover', true); },
    function() { $.data(this, 'hover', false); },
}).data('hover', false);

if ($(something).data('hover'))
    //Hovered!
SLaks
why use data() and not add/removeclass()? Is one more performant than the other?
psychotik
@psychotik: Yes; `$.data` doesn't involve string manipulation.
SLaks
A: 

You can use jQuery's mouseenter and mouseleave events. You can set a flag when the mouse enters the desired area and unset the flag when it leaves the area.

mikerobi
That's what I was thinking of doing. Using $.data() as SLaks suggests seems to be a good way to accomplish this.
JamesBrownIsDead
Then you should accept my answer by clicking the hollow check.
SLaks