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"
}
});
Call
What it does
event.relatedTarget
Learn 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
Parameter
Description
Step 1
Bind mouseout or mouseover on the element you care about.
Step 2
In the handler, read event.relatedTarget.
Step 3
Guard with if (event.relatedTarget) before using nodeName or jQuery.
Return Value
Return Value
Description
See examples
Check 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
);
}
});
currentTarget. The element the handler is bound to (here the same a via delegation).
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.