jQuery event.relatedTarget Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Events

Definition

event.relatedTarget is an Element on the jQuery event object — the other DOM node involved in a pointer move, if any. For mouseout, it is the element being entered; for mouseover, the element being exited. Added in jQuery 1.1.4.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
event.relatedTarget   // Element | null — read-only

// mouseout  → relatedTarget = element you are entering
// mouseover → relatedTarget = element you are leaving

$("a").on("mouseout", function (event) {
  if (event.relatedTarget) {
    console.log(event.relatedTarget.nodeName); // e.g. "DIV"
  }
});
CallWhat it does
event.relatedTargetLearn jQuery event.relatedTarget: the other DOM element in mouseover/mouseout, official anchor demo with nodeName, compare with target, null guards, examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Bind mouseout or mouseover on the element you care about.
Step 2In the handler, read event.relatedTarget.
Step 3Guard with if (event.relatedTarget) before using nodeName or jQuery.

Return Value

Return ValueDescription
See examplesCheck the examples below for what this API returns in common cases.

jQuery Examples

Example 1 — Official Demo: relatedTarget.nodeName

On mouseout from a link, log the element being entered.

jQuery
$("a").on("mouseout", function (event) {
  if (event.relatedTarget) {
    $("#out").text(
      "relatedTarget: " + event.relatedTarget.nodeName
    );
  }
});
Try It Yourself

How It Works

  1. Bind. mouseout fires when the pointer leaves the link.
  2. Other element. relatedTarget is where you are going.
  3. Guard. Skip if relatedTarget is null.

Example 2 — mouseover vs mouseout

Same property, opposite meaning of “the other” element.

jQuery
$("#zone").on("mouseover mouseout", function (event) {
  var rt = event.relatedTarget;
  var dir = event.type === "mouseover" ? "from" : "to";
  var name = rt
    ? rt.nodeName + (rt.id ? "#" + rt.id : "")
    : "(outside document)";
  $("#out").text(event.type + " — relatedTarget " + dir + ": " + name);
});
Try It Yourself

How It Works

  1. Two events. One handler for enter and leave.
  2. mouseover. relatedTarget is where you came from.
  3. mouseout. relatedTarget is where you are going.

Example 3 — target vs relatedTarget

See both sides of a pointer transition on the same event.

jQuery
$("#panel").on("mouseout", "a", function (event) {
  var rt = event.relatedTarget;
  $("#out").text(
    "target: " + event.target.nodeName + "\n" +
    "currentTarget: " + event.currentTarget.nodeName + "\n" +
    "relatedTarget: " + (rt ? rt.nodeName : "null")
  );
});
Try It Yourself

How It Works

  1. target. The link that fired mouseout.
  2. currentTarget. The element the handler is bound to (here the same a via delegation).
  3. relatedTarget. The element you moved into.

Frequently Asked Questions

event.relatedTarget is an Element on the jQuery event object. It is the other DOM element involved in the pointer move — for mouseout, the element being entered; for mouseover, the element being exited. Available since jQuery 1.1.4.
event.target is the element that received the event (often the deepest child under the pointer). event.relatedTarget is the other element in the transition — where the mouse came from or is going to.
Bind mouseout on anchors and read event.relatedTarget.nodeName — typically "DIV" when the pointer moves from the link into a sibling block element.
Prefer mouseover/mouseout when you need relatedTarget. mouseenter and mouseleave do not bubble and are a weaker fit for inspecting the adjacent element in all browsers.
Yes. When the pointer leaves the document (or enters from outside), relatedTarget may be null. Always guard with if (event.relatedTarget) before reading nodeName.
On mouseout of a trigger, check whether relatedTarget is still inside the menu container ($.contains or .closest). If the pointer moved into the panel, keep the menu open.

Next: event.result Property

Read the last non-undefined value returned by handlers on the same event.

event.result Property tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful