MouseEvent relatedTarget Property
Example
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 »
Description
The relatedTarget
property returns the element that triggered the mouse event.
The relatedTarget
property is read-only.
Note
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.
See Also:
Syntax
event.relatedTarget
Technical Details
Return Value: |
An Object. The related element. |
---|---|
DOM Version: | DOM Level 2 Mouse Events. |
Browser Support
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 |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.