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.
Remember
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"
}
});
Bind mouseover or mouseout, then read the other element — with a null check.
Bind mouseout or mouseover on the element you care about.
In the handler, read event.relatedTarget.
Guard with if (event.relatedTarget) before using nodeName or jQuery.
Compare with event.target when you need “this vs the other”.
For menus, test whether relatedTarget is still inside your widget ($.contains).
Piece
Required?
Role
mouseover / mouseout
Yes
Events that expose relatedTarget
event.relatedTarget
—
Other element (or null)
Null check
Recommended
Pointer may leave the document
$.contains / .closest
Optional
Keep menus open when moving inside
Pseudocode
Pseudocode
element.on("mouseout" | "mouseover", handler)
when pointer crosses a boundary:
event.target = element for this event
event.relatedTarget = the other element (or null)
if event.type == "mouseout":
relatedTarget = where we are going
if event.type == "mouseover":
relatedTarget = where we came from
if relatedTarget is null:
// left / entered the document — guard before use
Reference
Cheat Sheet
Keep these facts handy while tracing pointer transitions.
Topic
Detail
Type
Element property (or null)
Since
jQuery 1.1.4
mouseout
Element being entered
mouseover
Element being exited
Official demo
relatedTarget.nodeName on anchor mouseout
vs target
Other element vs event recipient
Null?
Yes — when leaving/entering the document
Mutates?
No — read-only
Try it
Live Preview
Move from the link into the sibling area — same idea as the official jQuery API demo.
Entered: DIV
— or —
relatedTarget is null (left document?)
How It Works
Check first. Never call .nodeName on a possible null.
Null path. Pointer left toward the chrome / outside the page.
Element path. Safe to read nodeName (or wrap with $()).
Habit. Always guard relatedTarget in production code.
Edge Cases & Pitfalls
Watch for these when using relatedTarget.
null
Can be null
Leaving or entering the document often yields null. Always check before reading properties.
events
Prefer mouseover / mouseout
relatedTarget is defined for those events. mouseenter / mouseleave are a weaker fit when you need the other element.
bubble
Child moves fire mouseout
mouseout bubbles and fires when moving between children. Use relatedTarget + $.contains (or switch to mouseleave) to ignore internal moves.
vs
Do not confuse with target
target is “this side” of the event; relatedTarget is “the other side.” They answer different questions.
Compatibility
Browser Support
event.relatedTarget is a jQuery event-object property (since 1.1.4). The underlying mouseover/mouseout related-target behavior is standard in modern browsers. Works wherever your loaded jQuery version runs.
✓ Stable · jQuery 1.1.4+
event.relatedTarget
Supported wherever jQuery 1.1.4+ is loaded. Prefer jQuery 3.x with .on("mouseover") / .on("mouseout") for modern code.
100%jQuery support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
event.relatedTarget1.1.4+
Bottom line: Safe for production. Guard null, prefer mouseover/mouseout, and use $.contains for hover menus.
Analysis
Performance Notes
Approach
Cost
Best for
Read relatedTarget
Negligible
Any mouseover/mouseout handler
$.contains(parent, rt)
Cheap
Menu / widget leave checks
Logging every mouseout
Can be chatty
Debug only — children fire often
Heavy DOM work on mouseout
Can stutter
Keep leave handlers light
Reading relatedTarget is free. Cost comes from noisy mouseout on nested trees — filter with contains or prefer mouseleave when you do not need the other element.
Remember
Key Takeaways
Role: the other element in a mouseover / mouseout move.
vs target:target is this side; relatedTarget is the other.
Always guard:relatedTarget can be null.
One line:relatedTarget answers “which other element is involved in this pointer move?”
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.