If you use the mousemove
event on the body tag. Is it possible to get what element in the html the mouse is currently over.
$('body').mousemove(function (e) {
var details = e; // can e.something return what element the mouse cursor is over?
console.log(details);
});
You can simply use the CSS :hover pseudo-class selector in combination with the jQuery mousemove() to check whether the mouse is over an element or not in jQuery.
The mouseover event is fired at an Element when a pointing device (such as a mouse or trackpad) is used to move the cursor onto the element or one of its child elements.
MouseMove is a simple event that is executed when a pointer is moving over or around an element. Mousemove is a javascript event that inside a web page. The mousemove event can also be understood as a part of an event handler, whereupon some action or movement by a mouse pointer, an intended script is executed.
Use e.target. For more information, you can check event.target documentation.
$('body').mousemove(function (e) {
var details = e.target; // can e.something return what element the mouse cursor is over?
console.log(details);
});
Here is the demo : http://jsfiddle.net/PaX7b/1/
You can use event.target
for getting id use
var id = event.target.id;
use can also check using this
var $target = $(event.target);
if ($target.is("a")) {
}
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