You mean you want the target of the onmouseover
event, so you can access the element's properties:
<script>
document.onmouseover = function(e) {
console.log(e.target.id);
}
</script>
Take a look at Event Properties for a cross-browser way to get the target (the following example is from the aforementioned website):
function doSomething(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
}
So to put those together:
document.onmouseover = function(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
console.log(targ.id);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…