Is there a function I can call to know if a certain element is currently being hovered over, like this?
/* Returns true or false */
hoveringOver("a#mylink");
The onmouseover event occurs when the mouse pointer is moved onto an element, or onto one of its children. Tip: This event is often used together with the onmouseout event, which occurs when a user moves the mouse pointer out of an element.
: to position (a computer cursor) over something (such as an image or icon) without selecting it Many in the class hovered their cursors over words and icons for long periods before committing to clicking their mouse.—
In computing, a mouseover , mouse hover or hover box is a graphical control element that is activated when the user moves or hovers the pointer over a trigger area, usually with a mouse, but also possible with a digital pen. Mouseover control elements are common in web browsers.
The mouseover event occurs when a mouse pointer comes over an element, and mouseout – when it leaves. These events are special, because they have property relatedTarget . This property complements target . When a mouse leaves one element for another, one of them becomes target , and the other one – relatedTarget .
You can use jQuery's hover
method to keep track:
$(...).hover(
function() { $.data(this, 'hover', true); },
function() { $.data(this, 'hover', false); }
).data('hover', false);
if ($(something).data('hover'))
//Hovered!
Yes, in classic JS:
document.getElementById("mylink").onmouseover = function() { alert("Hover!"); }
document.getElementById("mylink").onmouseout = function() { alert("Out!"); }
in jQuery:
$('#mylink').mouseover(function() {
alert("Hover!");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With