MouseEvent relatedTarget property

Definition and Usage

The relatedTarget property returns the element related to the element that triggered the mouse event.

The relatedTargert property can:

  • Used together with the mouseover event to indicate the element the cursor just exited
  • Or used together with the mouseout event to indicate the element the cursor just entered

Note:This property is read-only.

Example

Get the element that the cursor just exited:

<p onmouseover="getRelatedElement(event)">Mouse over this paragraph.</p>
<script>
function getRelatedElement(event) { 
  alert("The cursor just exited the " + event.relatedTarget.tagName + " element.");
}
</script>

Try It Yourself

Syntax

event.relatedTarget

Technical Details

Return Value: Reference to the related element.
DOM Version: DOM Level 2 Events

Browser Support

Properties Chrome IE Firefox Safari Opera
relatedTarget Support Support Support Support Support