Reputation: 168239
How can I get the (innermost) DOM object that the mouse cursor points to? Unlike other events, a keyup event's e.target
returns only a rough object like html body. I want to know the innermost DOM object on keyup events, just like what is returned by e.target
of a click
event.
Upvotes: 0
Views: 150
Reputation: 186063
Here:
document.body.onmousemove = function ( e ) {
var topmost = document.elementFromPoint( e.clientX, e.clientY );
};
Live demo: http://jsfiddle.net/yVtsn/1/
Upvotes: 3
Reputation: 35304
If you're open to jQuery...
There's a really cool function called document.elementFromPoint
which does what it sounds like.
What we need is to find the x and y coords of the mouse and then call it using those values:
var x = event.clientX, y = event.clientY,
elementMouseIsOver = document.elementFromPoint(x, y);
Upvotes: 3