Is there a quick & easy way to do this in jQuery that I'm missing?
I don't want to use the mouseover event because I'm already using it for something else. I just need to know if the mouse is over an element at a given moment.
I'd like to do something like this, if only there was an "IsMouseOver" function:
function hideTip(oi) {
setTimeout(function() { if (!IsMouseOver(oi)) $(oi).fadeOut(); }, 100);
}
I see timeouts used for this a lot, but in the context of an event, can't you look at coordinates, like this?:
Depending on context, you may need to make sure (this==e.target) before calling areXYInside(e).
fyi- I'm looking at using this approach inside a dragLeave handler, in order to confirm that the dragLeave event wasn't triggered by going into a child element. If you don't somehow check that you're still inside the parent element, you might mistakenly take action that's meant only for when you truly leave the parent.
EDIT: this is a nice idea, but does not work consistently enough. Perhaps with some small tweaks.
You can use
is(':visible');
in jquery And for $('.item:hover') it is working in Jquery also.this is a htm code snnipet :
and this is the JS Code :
this what i was talking about :)
A clean and elegant hover check:
Thanks to both of you. At some point I had to give up on trying to detect if the mouse was still over the element. I know it's possible, but may require too much code to accomplish.
It took me a little while but I took both of your suggestions and came up with something that would work for me.
Here's a simplified (but functional) example:
And then to make this work on some text this is all I have to do:
Along with a lot of fancy CSS, this allows some very nice mouseover help tooltips. By the way, I needed the delay in the mouseout because of tiny gaps between checkboxes and text that was causing the help to flash as you move the mouse across. But this works like a charm. I also did something similar for the focus/blur events.
I have answered this in another question, with all details you may need:
Detect IF hovering over element with jQuery (has 99 upvotes at the time of writing)
Basically, you can do something like:
This works only if
oi
is a jQuery object containing a single element. If there are multiple elements matched, you need to apply to each element, for example:This was tested starting jQuery 1.7.
WARNING:
is(':hover')
is deprecated in jquery 1.8+. See this post for a solution.You can also use this answer : https://stackoverflow.com/a/6035278/8843 to test if the mouse is hover an element :