MouseEvent relatedTarget Property - Javascript DOM

Javascript examples for DOM:Mouse Event

Description

The relatedTarget property returns the element related to the element.

In the mouseover event the relatedTargert property indicates the element the cursor just exited.

In the mouseout event the relatedTargert property indicate the element the cursor just entered.

This property is read-only.

The following code shows how to get the element the cursor just exited:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p onmouseover="getRelatedElement(event)">Mouse over this paragraph.</p>

<script>
function getRelatedElement(event) {
    console.log("The cursor just exited the " + event.relatedTarget.tagName + " element.");
}
</script>//  w ww .  java 2  s.  c  om

</body>
</html>

Related Tutorials