Reputation: 12307
How to get the id of the div on which the mouse is currently pointing?
Upvotes: 2
Views: 13053
Reputation: 38516
You can use a javascript variable to store the current hovered div.. jQuery (or standard JS) could be used to set the event handler to populate the variable.
Visible test at: http://jsfiddle.net/gfosco/Hys7r/
Upvotes: 2
Reputation: 11238
I think your best bet is to track mouseover
at the document
level and maintain the id of the last element hit.
var lastID = null;
var handleMouseover = function (e) {
var target = e.target || e.srcElement;
lastID = target.id;
};
if (document.addEventListener) {
document.addEventListener('mouseover', handleMouseover, false);
}
else {
document.attachEvent('onmouseover', handleMouseover);
}
Upvotes: 8
Reputation: 31560
<div id="the-id" onmouseover="alert(this.id)">some text</div>
Upvotes: 2