jQuery mouseout Event

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Mouse events

What You’ll Learn

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

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 mouseout event (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.

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.

📝 Syntax

The modern jQuery API for the mouseout event has two main forms — binding a handler and triggering the event:

1. Bind a handler — .on("mouseout" [, eventData ], handler) (since 1.7)

jQuery
.on( "mouseout" [, eventData ], handler )
  • eventData — optional object passed to the handler as event.data.
  • handler — function called each time mouseout fires: function( event ) { ... }. Use event.relatedTarget to detect where the pointer moved.

2. Event delegation — .on("mouseout", selector, handler)

jQuery
$( "#menu" ).on( "mouseout", "li", function( event ) {
  // runs when pointer leaves any li inside #menu — bubbles from children
} );

3. Trigger the event — .trigger("mouseout") (since 1.0)

jQuery
.trigger( "mouseout" )
  • Runs bound mouseout handlers on the matched element(s).
  • Use .triggerHandler("mouseout") to run handlers without bubbling.

4. Unbind — .off("mouseout" [, selector] [, handler])

jQuery
$( "#outer" ).off( "mouseout" );              // remove all mouseout handlers
$( "#menu" ).off( "mouseout", "li", fn );     // remove delegated handler

Official jQuery API examples

jQuery
$( "#outer" ).on( "mouseout", function() {
  $( "#log" ).append( " Handler for `mouseout` called." );
} );

$( "#other" ).on( "click", function() {
  $( "#outer" ).trigger( "mouseout" );
} );

Return value

  • .on() and .trigger() return the original jQuery object for chaining.
  • Handler return values are ignored unless you use return false (equivalent to preventDefault() + stopPropagation()).

⚡ Quick Reference

GoalCode
Bind mouseout handler$("#box").on("mouseout", fn)
Pair over and out (legacy).on("mouseover", show).on("mouseout", hide)
Filter child crossingsif ($(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")

📋 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

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.

jQuery
$( "#outer" ).on( "mouseout", function() {
  $( "#log" ).append( " Handler for `mouseout` called." );
} );
Try It Yourself

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.

jQuery
$( "#outer" ).on( "mouseout", function() {
  $( "#log" ).append( " Handler for `mouseout` called." );
} );

$( "#other" ).on( "click", function() {
  $( "#outer" ).trigger( "mouseout" );
} );
Try It Yourself

How It Works

.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 );
  } );
Try It Yourself

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 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.

jQuery
$( ".card" )
  .on( "mouseover", function() {
    $( this ).addClass( "highlight" );
  } )
  .on( "mouseout", function() {
    $( this ).removeClass( "highlight" );
  } );
Try It Yourself

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.

🚀 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.

📝 Notes

  • Bind with .on("mouseout", handler) since jQuery 1.7 — not the deprecated .mouseout(handler) method.
  • Trigger with .trigger("mouseout") since jQuery 1.0.
  • mouseout bubbles — 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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
mouseout Universal

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.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Six things to remember about the mouseout event

Bubbles, filter, prefer leave.

6
Core concepts
02

.trigger()

Fire

Programmatic
bubble 03

vs mouseleave

Bubbles

Compare
target 04

relatedTarget

Filter

Pattern
over 05

mouseover pair

Legacy

Hover
.off 06

.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.

Next: .mouseout() Method

Learn the deprecated shorthand — and how to migrate to .on("mouseout").

.mouseout() tutorial →

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.

6 people found this page helpful