relatedTarget event attribute


relatedTarget Event attributes


Definition and usage


relatedTarget The event attribute returns the target node related to the event node.

For the mouseover event, this property is the node that the mouse pointer leaves when it moves to the target node.

For the mouseout event, this property is the node that the mouse pointer enters when leaving the target.

For other types of events, this attribute is not useful.

Syntax

event.relatedTarget

Example

Example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
function getRelatedElement(event){ 
	alert("鼠标指针移到了 " + event.relatedTarget.tagName + " 元素");
}
</script>
</head>
<body>

<p onmouseover="getRelatedElement(event)">鼠标移到这一段。</p>

</body>
</html>

Run Instance»

Click the "Run Instance" button to view the online instance