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
2010-05-17 02:54:31
why use data() and not add/removeclass()? Is one more performant than the other?
psychotik
2010-05-17 03:20:03
@psychotik: Yes; `$.data` doesn't involve string manipulation.
SLaks
2010-05-17 03:32:23
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
2010-05-17 02:59:21
That's what I was thinking of doing. Using $.data() as SLaks suggests seems to be a good way to accomplish this.
JamesBrownIsDead
2010-05-17 03:01:27