MouseEvent.relatedTarget is the secondaryEventTarget for enter/leave style mouse events—the other element the pointer came from or went to. Learn MDN’s target vs relatedTarget table, when the value is null, and five try-it labs.
01
Kind
Instance property
02
Returns
EventTarget | null
03
Status
Baseline Widely available
04
Used on
over / out / enter / leave
05
Also
dragenter / dragleave
06
Safe read
Null-check first
Fundamentals
Introduction
When the pointer slides from a red box into a blue box, event.target tells you one side of the story. relatedTarget tells you the other side—where you came from on mouseover, or where you went on mouseout.
JavaScript
el.addEventListener("mouseover", (event) => {
console.log(event.target); // element entered
console.log(event.relatedTarget); // element exited (or null)
});
💡
Beginner tip
Always write event.relatedTarget ? event.relatedTarget.id : "unknown" (as MDN does). A missing secondary target is null, and reading .id on null throws.
Concept
Understanding the Property
MDN: MouseEvent.relatedTarget is the secondary target for the mouse event, if there is one. For events with no secondary target, it returns null. FocusEvent.relatedTarget is a similar property for focus events.
Instance — read event.relatedTarget in a handler.
EventTarget or null — often an Element; sometimes missing.
Secondary — complements event.target on transition events.
Read-only — may be set via constructor options on synthetic events.
MouseEvent.relatedTarget is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
MouseEvent.relatedTarget
Reliable secondary EventTarget for mouseover/out/enter/leave and drag enter/leave.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in modern IE versions
Full support
relatedTargetExcellent
Bottom line: Read event.relatedTarget on transition events; always null-check before using it.
Wrap Up
Conclusion
event.relatedTarget is the secondary element in pointer enter/leave transitions. Pair it with event.target, null-check before reading properties, and use MDN’s event table to remember which role each event uses.
Use it on over/out/enter/leave (and drag enter/leave)
Keep MDN’s target / relatedTarget table nearby
Prefer clear ids when debugging transitions
Test hover menus that care about the “other” element
❌ Don’t
Assume relatedTarget is set on every mouse event
Read properties on null without a guard
Confuse it with event.target
Forget that roles swap between over and out
Mutate event.relatedTarget on live user events
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about relatedTarget
Secondary EventTarget for mouse transition events.
5
Core concepts
🖱️01
Instance
on the event
Kind
🎯02
Secondary
other element
Role
🔢03
Nullable
EventTarget | null
Type
📈04
Transitions
over / out / enter
Events
🛡️05
Baseline
widely available
Status
❓ Frequently Asked Questions
It is a read-only secondary EventTarget for certain mouse (and drag) events—the other element involved when the pointer moves between nodes. If there is no secondary target, it is null.
No. MDN marks MouseEvent.relatedTarget as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard, so no status warning banner is needed.
MDN lists mouseenter, mouseleave, mouseout, mouseover, dragenter, and dragleave. For each, target and relatedTarget describe which element you entered and which you exited (roles swap by event type).
For events with no secondary target—or when the other side is outside the document—relatedTarget is null. Always null-check before reading .id or other properties.
event.target is the primary element for the event. relatedTarget is the other element in enter/leave/over/out transitions. On a plain click, relatedTarget is typically null.
Yes. FocusEvent.relatedTarget is a similar secondary target for focus and blur events.
Did you know?
Focus events have their own twin: FocusEvent.relatedTarget. The idea is the same—a secondary target that describes the other end of a focus move—just for keyboard/focus instead of the mouse.