Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing an element that is currently being hovered by mouse, from anywhere in the document [closed]

Is there any way that I can access an element that currently has mouse hovered over it using jquery?

I know that I can access an element by attaching mouseover event to an element, but how about when I haven't applied any event to an element and want to access that specific element which is being hovered over by the mouse from any where in the document?

like image 742
Kamran Ahmed Avatar asked Sep 03 '25 10:09

Kamran Ahmed


1 Answers

You can attach the mouseover event to the document and get the current element being hovered by using event.target.

Try,

$(document).mouseover(function(e){
  console.log($(e.target).attr('id')); // i just retrieved the id for a demo
});
like image 148
Rajaprabhu Aravindasamy Avatar answered Sep 05 '25 01:09

Rajaprabhu Aravindasamy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!