Get the element the cursor just exited:
<div onmouseover="getRelatedElement(event)">
</div>
<script>
function getRelatedElement(event) {
let text = "The cursor entered " + event.relatedTarget.tagName;
}
</script>
Try it Yourself »
The relatedTarget
property returns the element that triggered the mouse event.
The relatedTarget
property is read-only.
The relatedTarget
property can be used with the mouseover
event, to get the element the cursor entered, or the mouseout
event, to get the element the cursor exited.
event.relatedTarget
Return Value: | An Object. The related element. |
---|---|
DOM Version: | DOM Level 2 Mouse Events. |
event.relatedTarget
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!