The mouseout event fires when the mouse pointer leaves an element. This tutorial covers binding with .on("mouseout"), triggering with .trigger("mouseout"), understanding bubbling and event.relatedTarget, comparing mouseout with mouseleave, and when to prefer mouseleave for nested menus.
01
.on()
Bind handler
02
.trigger()
Fire out
03
bubbles
Child crosses
04
relatedTarget
Filter false
05
mouseover
Legacy pair
06
Since 1.7
Modern API
Fundamentals
Introduction
Every hover interaction has an exit — dropdowns close, tooltips disappear, and highlight classes are removed when the pointer leaves. jQuery’s mouseout event is the classic way to run JavaScript at that moment, but its bubbling behavior can surprise developers working with nested elements.
The official jQuery API distinguishes the mouseoutevent (bound with .on("mouseout") since 1.7) from the deprecated .mouseout()method used in older code. Unlike mouseleave, mouseout bubbles — it fires when leaving the bound element or when moving from the parent into a child inside it. To programmatically fire a handler, use .trigger("mouseout") — available since jQuery 1.0.
Concept
Understanding the mouseout Event
The mouseout event is sent to an element when the mouse pointer leaves that element. Because it bubbles, moving from a parent into a child inside the bound element also triggers mouseout on the parent — the event trickles up the DOM tree just like a physical exit.
This bubbling behavior causes headaches with nested menus and tooltips. When the pointer moves from a menu item into its submenu, mouseout fires on the parent container — making it look like the user left the menu entirely. For nested content, jQuery recommends mouseleave paired with mouseenter instead. If you must use mouseout, inspect event.relatedTarget to filter false positives.
💡
Beginner Tip
For hover menus with submenus, prefer mouseenter + mouseleave over mouseover + mouseout. If you inherit legacy mouseout code on nested elements, check event.relatedTarget — when it is still inside the bound container, ignore the event.
Foundation
📝 Syntax
The modern jQuery API for the mouseout event has two main forms — binding a handler and triggering the event:
.on() and .trigger() return the original jQuery object for chaining.
Handler return values are ignored unless you use return false (equivalent to preventDefault() + stopPropagation()).
Cheat Sheet
⚡ Quick Reference
Goal
Code
Bind mouseout handler
$("#box").on("mouseout", fn)
Pair over and out (legacy)
.on("mouseover", show).on("mouseout", hide)
Filter child crossings
if ($(event.relatedTarget).closest("#outer").length) return;
Delegated mouseout on children
$("#menu").on("mouseout", "li", fn)
Trigger mouseout programmatically
$("#outer").trigger("mouseout")
Prefer for nested menus
$("#nav").on("mouseleave", fn) instead of mouseout
Remove mouseout handlers
$("#box").off("mouseout")
Compare
📋 mouseout vs mouseleave vs mouseover vs CSS :hover
Four ways to respond when the pointer exits or moves over elements — choose the event that matches your hover needs.
mouseout
bubbles
Re-fires on every child boundary crossing — legacy hover pair with mouseover; filter with relatedTarget
mouseleave
exit once
Fires only when pointer exits bound element entirely — recommended for nested menus and tooltips
mouseover
bubbles
Enter counterpart to mouseout — pair for legacy hover; prefer mouseenter for nested content
CSS :hover
style only
Stylesheet pseudo-class — no JavaScript; use for simple color or visibility changes
Hands-On
Examples Gallery
Examples 1–3 follow the official jQuery API documentation. Examples 4–5 cover event.relatedTarget filtering and the legacy mouseover + mouseout hover pair. Use the Try-it links to run each snippet in the browser.
📚 Binding & Triggering
Official jQuery demos for mouseout handlers and programmatic triggers.
Example 1 — Official Demo: Bind Handler on #outer
Append a log message when the pointer leaves the outer element — the canonical .on("mouseout") pattern.
Pointer leaves #outer → #log appends: "Handler for mouseout called."
Moving from Outer into Inner child → handler ALSO fires (bubbles)
mouseout fires when leaving element OR crossing into a child
How It Works
.on("mouseout", fn) registers the function on #outer. jQuery calls it when the pointer crosses out of the outer boundary and when moving from the outer area into the inner child — that bubbling behavior is the key difference from mouseleave.
Example 2 — Official Demo: #other Triggers mouseout on #outer
One element programmatically fires the mouseout handler on another.
.trigger("mouseout") synthetically fires the mouseout event on #outer, running the same handler as a physical pointer exit. Useful for testing hide behavior or keyboard-accessible fallbacks.
Example 3 — Official Demo: mouseout vs mouseleave
Side-by-side comparison from the mouseout perspective — the left box re-fires on every child boundary crossing; the right box does not.
jQuery
var i = 0;
$( "div.overout" )
.on( "mouseover", function() {
$( "p", this ).first().text( "mouse over" );
} )
.on( "mouseout", function() {
$( "p", this ).first().text( "mouse out" );
$( "p", this ).last().text( ++i );
} );
var n = 0;
$( "div.enterleave" )
.on( "mouseenter", function() {
$( "p", this ).first().text( "mouse enter" );
} )
.on( "mouseleave", function() {
$( "p", this ).first().text( "mouse leave" );
$( "p", this ).last().text( ++n );
} );
Left box (mouseout): leave counter increments when exiting outer AND inner child
Right box (mouseleave): leave counter increments only when exiting outer boundary
Move between outer and inner on left → count jumps; on right → stable
How It Works
The official API demo uses nested divs with an inner yellow child. mouseout on the left box bubbles — crossing out of the inner div counts as a leave event on the parent. mouseleave on the right ignores child crossings — the counter increments only when the pointer exits the entire outer box. For nested menus, choose the right box pattern.
📈 Filtering & Legacy Hover Pairs
Practical patterns for taming mouseout bubbling and legacy over/out hover code.
Example 4 — Filter with event.relatedTarget
Ignore mouseout events where the pointer moved to a child still inside the bound container — reduces false positives without switching events.
jQuery
$( "#outer" ).on( "mouseout", function( event ) {
if ( $( event.relatedTarget ).closest( "#outer" ).length ) {
return; // pointer moved to a child — still inside #outer
}
$( "#log" ).append( " Left #outer entirely." );
} );
Move from Outer into Inner → relatedTarget is inside #outer → handler returns early
Leave #outer entirely → relatedTarget is outside → log appends "Left #outer entirely."
Filters bubbling false positives on nested content
How It Works
event.relatedTarget tells you where the pointer went. Wrapping it with $(event.relatedTarget).closest("#outer") checks whether the destination is still inside the bound container. If so, the user has not truly left — skip the handler. This is the standard workaround when you cannot migrate to mouseleave.
Example 5 — Legacy Hover: mouseover + mouseout on Cards
Add highlight on over, remove on out — the classic pre-mouseenter hover pair. Works on flat cards; beware nested content inside each card.
Enter a .card → .highlight class added (mouseover)
Leave the card → .highlight removed (mouseout)
Nested caveat: moving between child elements inside a card re-fires mouseout/mouseover — use mouseenter/mouseleave or relatedTarget filter instead
How It Works
mouseover handles the show half; mouseout handles the hide half. On simple flat cards without nested children, this pair works fine. When cards contain buttons, icons, or nested spans, moving between those children triggers spurious out/over events — migrate to mouseenter + mouseleave for stable behavior.
Applications
🚀 Common Use Cases
Legacy hover pairs — maintain existing mouseover / mouseout code on flat elements without nested children.
Filter with relatedTarget — ignore child-boundary crossings when refactoring away from mouseout is not yet possible.
Remove row highlight — $("tr").on("mouseout", fn) on table rows with no nested interactive elements.
Hide flat tooltips — dismiss a tooltip when leaving a trigger that has no nested content inside it.
Event delegation — $("#list").on("mouseout", "li", fn) when list items have no nested children.
Programmatic testing — $("#box").trigger("mouseout") to verify hide logic in unit tests.
🧠 How mouseout Bubbling Differs from mouseleave
1
Pointer inside outer box
User hovers over the bound element — no out event yet.
inside
2
Pointer moves to child
mouseout fires on the parent and bubbles up. mouseleave stays silent — still inside the outer boundary.
child cross
3
Filter or switch events
Check event.relatedTarget to ignore child crossings, or bind mouseleave instead for nested menus.
relatedTarget
4
👉
Stable hide
For nested menus and tooltips, use mouseenter + mouseleave — one enter, one leave, no premature collapse from bubbling.
Important
📝 Notes
Bind with .on("mouseout", handler) since jQuery 1.7 — not the deprecated .mouseout(handler) method.
Trigger with .trigger("mouseout") since jQuery 1.0.
mouseoutbubbles — unlike mouseleave, it fires when moving from parent into a child.
Use event.relatedTarget to filter false positives when the pointer moves to a child still inside the bound element.
For nested menus and tooltips, prefer mouseenter + mouseleave over mouseover + mouseout.
Any HTML element can receive mouseout — not limited to links or buttons.
Use .off("mouseout") to remove handlers — avoid deprecated .unbind("mouseout").
Touch devices have no true hover — provide click/tap fallbacks for critical UI.
Compatibility
Browser Support
The native mouseout event is supported in all browsers jQuery targets. jQuery’s .on("mouseout") (since 1.7) and .trigger("mouseout") (since 1.0) provide consistent collection binding, eventData, delegation, and programmatic triggering across browsers.
✓ jQuery 1.7+
jQuery mouseout event
Supported in jQuery 1.x, 2.x, and 3.x across all modern browsers. Native equivalent: element.addEventListener('mouseout', fn) — universal support; jQuery adds collection binding, eventData, delegation, and .trigger().
100%With jQuery loaded
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
mouseoutUniversal
Bottom line: Safe in any jQuery project. Prefer .on('mouseout') over deprecated .mouseout() for binding. For nested content, use mouseleave or filter with event.relatedTarget.
Wrap Up
Conclusion
The jQuery mouseout event fires when the pointer leaves an element — and because it bubbles, it also fires when moving from a parent into a child inside the bound element. Bind handlers with .on("mouseout", fn), inspect event.relatedTarget to filter false positives, and fire handlers programmatically with .trigger("mouseout").
Choose mouseleave over mouseout when nested content would cause menus or tooltips to collapse prematurely. Use the legacy mouseover + mouseout pair only on flat elements without nested children. Replace deprecated .mouseout(handler) with .on("mouseout", handler). For touch devices, remember hover has no mobile equivalent — add click fallbacks where needed.
Bind with .on("mouseout", handler) — the modern, delegation-capable API
Prefer mouseenter + mouseleave for nested menus and tooltips
Filter child crossings with event.relatedTarget when stuck on mouseout
Use CSS :hover when only colors or visibility change
Call .off("mouseover mouseout") when removing legacy hover behavior
❌ Don’t
Use deprecated .mouseout(handler) for new code — use .on("mouseout")
Bind mouseout on containers with nested submenus without filtering
Assume one mouseout equals one true exit — bubbling fires on child crossings too
Rely on hover alone for critical mobile UI — add tap/click fallbacks
Forget to unbind over/out handlers when tearing down SPAs
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about the mouseout event
Bubbles, filter, prefer leave.
6
Core concepts
.on01
.on("mouseout")
Bind
API
⚡02
.trigger()
Fire
Programmatic
bubble03
vs mouseleave
Bubbles
Compare
target04
relatedTarget
Filter
Pattern
over05
mouseover pair
Legacy
Hover
.off06
.off("mouseout")
Unbind
Cleanup
❓ Frequently Asked Questions
The mouseout event fires when the mouse pointer leaves an element. In modern jQuery, bind handlers with .on('mouseout', handler) since version 1.7. Unlike mouseleave, mouseout bubbles — it re-fires when the pointer moves from a parent into a child inside the bound element. Any HTML element can receive mouseout.
When the pointer leaves a child element, mouseout bubbles up to ancestor elements bound with .on('mouseout'). A handler on the outer menu container fires even though the user is still inside the menu — moving into a submenu looks like leaving the parent. That premature firing collapses dropdowns and flickers hover styles. For nested menus, prefer mouseenter and mouseleave instead.
event.relatedTarget is the DOM element the pointer moved to when mouseout fired. If relatedTarget is still inside the bound element (for example, a child div), you can ignore the event: if ($(event.relatedTarget).closest('#outer').length) return;. This filters false positives caused by bubbling across child boundaries without switching to mouseleave.
mouseout bubbles and fires when leaving the bound element OR when moving from the parent into a child inside it. mouseleave fires only when the pointer exits the bound element entirely — child crossings are ignored. For hover menus, tooltips, and containers with nested content, mouseleave (paired with mouseenter) avoids menus collapsing when the user moves into a submenu.
Call .trigger('mouseout') on the target element: $('#outer').trigger('mouseout'). Available since jQuery 1.0, trigger runs bound mouseout handlers. To run handlers without bubbling, use .triggerHandler('mouseout') instead.
The deprecated .mouseout(handler) method binds a mouseout handler directly on the collection — it is shorthand for .on('mouseout', handler) in older jQuery. For new code, use .on('mouseout', fn) instead of .mouseout(fn). The event name is the same; only the binding API changed when .on() became the standard in jQuery 1.7.
Did you know?
The jQuery API documentation explicitly warns that mouseout “can cause many headaches due to event bubbling” and points developers to mouseleave as a useful alternative. When the pointer leaves the inner child of a nested box, mouseout fires on the inner element first, then bubbles to the outer — triggering hide logic at inopportune times. jQuery added proprietary mouseenter and mouseleave events (originally IE-only) specifically to solve this problem.