I use the following snippet to define in Chrome / Safari and FF if the user is hanging over the anchor.
var isURL = $("a", obj).is(":hover");
I saw different posts about: hover, which is a CSS selector, but what I canβt understand is why the code returns true if obj has 1 link, but throws an unrecognized javascript expression error if there are 2 or more.
Here is the fiddle: hover working: - http://jsfiddle.net/2kyaJ/122/
Same thing but a few elements (doesn't work): - http://jsfiddle.net/2kyaJ/121/
Can someone explain this to me?
By the way, I saw this ... How to check if the mouse is over an element in jQuery?
4 years later, is this even the best and, it would seem, only a way to determine that the user is hanging over an element? If so, can anyone provide an example?
Edit: it was necessary to fish exactly as I needed, but it turned out that it was as simple as working well.
I am currently using it inside a plugin with jQuery 1.9.1, where I start the animation when I hover over the parent element (obj). Hope someone else finds this useful in the future. Use .length instead of .size, since .size is deprecated from version 1.8 onwards.
function isMouseOver() {
if ($('a:hover', obj).length != 0) {
return true;
} else {
return false;
}
}
Using:
var isURL = isMouseOver();