Return the related target of an element:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>/* w w w .j a v a 2 s . com*/ <script> $(document).ready(function(){ $("div, p").mouseenter(function(event){ $("#msg").html("Related target is: " + event.relatedTarget.nodeName); }); }); </script> </head> <body> <div style="height:200px;border:solid">This is a div element <p style="background-color:pink">This is a paragraph</p> </div><br> <div id="msg" /> </body> </html>
The event.relatedTarget property returns which element being entered or exited on mouse movement.
event.relatedTarget
Parameter | Optional | Description |
---|---|---|
event | Required. | The event parameter comes from the event binding function |