jQuery event.relatedTarget Property


The event.relatedTarget property in jQuery is used to return which element being entered or exited on mouse movement.

Syntax

The syntax is as follows −

event.relatedTarget

Example

Let us now see an example to implement the jQuery event.relatedTarget property −

<!DOCTYPE html>
<html>
<head>
<style>
   .demo {
      border:2px solid yellow;
   }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("div, p").mouseenter(function(event){
         $("#demo").html("Related target = " + event.relatedTarget.nodeName);
      });
   });
</script>
</head>
<body>
<h2>Demo Heading</h2>
<div class="demo">This is a demo text.
<p style="color: red">This is a demo line.</p>
</div><br>
<div id="demo" />
</body>
</html>

Output

This will produce the following output −

Now, place the mouse cursor inside the div (box) −

Updated on: 12-Nov-2019

89 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements