jQuery mouseout Event

Beginner
8 min read
Updated: Oct 2026
5 examples
Live preview

What Is mouseout?

The mouseout event fires when the pointer leaves an element (bound with .on("mouseout") since jQuery 1.7). It bubbles — leaving a child also notifies the parent. Pair historically with mouseover; for nested UI prefer mouseleave / mouseenter.

Remember
$("#outer").on("mouseout", function (event) { … })

bubbles: parent → fires when leaving OR entering a child
mouseleave: fires only when exiting the element entirely

event.relatedTarget → element the pointer moved to
.trigger("mouseout") → run handlers manually
NeedUse
Bind leave handler$el.on("mouseout", fn)
Nested menus / tooltips.on("mouseleave", fn)
Filter child crossingsevent.relatedTarget
Fire manually$el.trigger("mouseout")

How to Use mouseout

Bind a leave handler, account for bubbling, and prefer mouseleave when nesting matters.

  1. Select the element that should react when the pointer leaves.
  2. Bind with .on("mouseout", handler).
  3. If children exist, check event.relatedTarget — or switch to mouseleave.
  4. Unbind with .off("mouseout") when the feature is done.
PieceRequired?Role
ElementYesReceives leave (and child-crossing) events
handlerYesfunction(event) { … }
eventDataOptionalObject passed as event.data
Return—jQuery object (chainable)

Pseudocode

Pseudocode
on mouseout of #outer:
  to = event.relatedTarget   // where the pointer went

  // Bubbling case: Outer → Inner still fires mouseout on Outer
  if to is still inside #outer:
    optionally ignore  // or use mouseleave instead
  else:
    run leave logic (hide menu, remove class, …)

Cheat Sheet

Keep these facts handy when handling pointer leave.

TopicDetail
Bind.on("mouseout", handler) (1.7+)
Trigger.trigger("mouseout") (1.0+)
Bubbles?Yes — child crossings notify the parent
vs mouseleavemouseleave ignores child crossings
relatedTargetElement the pointer moved into
Legacy pairmouseover + mouseout
Shorthand.mouseout() deprecated — use .on()

Live Preview

Move between Outer and Inner. Watch how often mouseout fires compared with mouseleave.

Outer

Official idea: mouseout re-fires on child crossings; mouseleave does not.

Result
mouseout count: 0
mouseleave count: 0

Move in/out of Outer and Inner

jQuery Examples

Short, copy-ready snippets. Open each Try It Yourself lab for a live editor.

Example 1 — Bind Handler on #outer

Official pattern: log when the pointer leaves the outer element — including into a child.

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

How It Works

  1. Bind the event. .on("mouseout", fn) registers the handler on #outer.
  2. Leave the element. Exiting to the page runs the function.
  3. Cross into a child. Moving Outer → Inner also fires because of bubbling.
  4. Expect many calls. Nested content produces more leave events than mouseleave.

Example 2 — Trigger from Another Element

Click a button to fire the same handler with .trigger("mouseout").

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

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

How It Works

  1. Same handler. Real leaves and triggers both call the bound function.
  2. Synthetic event. .trigger("mouseout") runs handlers without a real pointer move.
  3. Bubbling still applies. Use .triggerHandler("mouseout") to avoid bubble side effects.
  4. Useful for tests. Simulate leave logic without moving the mouse.

Example 3 — mouseout vs mouseleave

Official comparison: count leave events on nested boxes — adapted from the jQuery API demo.

jQuery
var i = 0;
$(".overout").on("mouseout", function () {
  $("span", this).text(++i);
});

var n = 0;
$(".enterleave").on("mouseleave", function () {
  $("span", this).text(++n);
});
Try It Yourself

How It Works

  1. Left box uses mouseout. Every child boundary can increment the counter.
  2. Right box uses mouseleave. Only a full exit increments.
  3. Same nesting. The HTML shape is identical — only the event differs.
  4. Rule of thumb. Nested UI → prefer mouseleave.

Example 4 — Filter with event.relatedTarget

Ignore false leaves when the pointer moves to a child still inside #outer.

jQuery
$("#outer").on("mouseout", function (event) {
  if ($(event.relatedTarget).closest("#outer").length) {
    return; // still inside #outer
  }
  $("#log").append("Left #outer entirely.\n");
});
Try It Yourself

How It Works

  1. Read destination. relatedTarget is where the pointer went.
  2. Check ancestry. .closest("#outer") asks if that node is still inside.
  3. Early return. Child crossings are ignored.
  4. True exit. Only leaving the whole container updates the log.

Example 5 — mouseover + mouseout on Flat Cards

Legacy hover pair works well on flat elements without nested interactive children.

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

// Nested content? Prefer mouseenter / mouseleave instead.
Try It Yourself

How It Works

  1. Enter with mouseover. Adds a class when the pointer arrives.
  2. Leave with mouseout. Removes the class when the pointer exits.
  3. Flat targets. No nested buttons/links → fewer false leaves.
  4. Better default. For nested UI, switch to mouseenter / mouseleave.

Edge Cases & Pitfalls

Check these before closing menus or tooltips with mouseout.

bubble

Child crossings look like exits

Outer → Inner fires mouseout on Outer. Menus can collapse mid-hover.

prefer

Use mouseleave for nested UI

Official guidance: see mouseleave for a stable alternative to bubbling leave events.

null

relatedTarget can be null

Leaving the window or some synthetic triggers leave it empty — guard before calling methods on it.

css

Prefer CSS :hover for style-only

If you only change colors or visibility, CSS avoids JS leave bugs entirely.

deprecated

.mouseout() shorthand

Deprecated since 3.3 — bind with .on("mouseout") instead.

Browser Support

The mouseout event is a standard DOM mouse event. jQuery’s .on("mouseout") (since 1.7) works in any browser where your jQuery build runs.

✓ jQuery 1.7+ · Browsers

jQuery mouseout event

Supported wherever jQuery runs — Chrome, Firefox, Safari, Edge, and legacy environments with a matching jQuery build.

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 Browsers

Bottom line: Safe in all common browsers with jQuery loaded. Prefer .on() / .off() over the deprecated .mouseout() shorthand.

Performance Notes

ApproachCostBest for
mouseout on nested treesMore handler callsLegacy / flat targets only
mouseleaveFewer leave callsMenus, tooltips, cards with children
relatedTarget filterSmall closest() checkKeeping mouseout without flicker

Bubbling leave events are not “slow” by themselves — but extra handler runs (class toggles, DOM writes) add up. Prefer mouseleave when nesting is deep.

Key Takeaways

  • Role: run logic when the pointer leaves an element.
  • Bubbles: child crossings notify the parent — unlike mouseleave.
  • Filter: use event.relatedTarget or switch to mouseleave.
  • API: prefer .on("mouseout"), not the deprecated .mouseout() shorthand.

One line: mouseout leaves and bubbles — reach for mouseleave when nesting matters.

Frequently Asked Questions

mouseout fires when the pointer leaves an element. Bind with .on('mouseout', handler) (since jQuery 1.7). Unlike mouseleave, it bubbles — it also fires when moving from a parent into a child inside the bound element.
When the pointer leaves a child, mouseout bubbles to ancestors. A handler on an outer menu can fire even though the user is still inside the menu. Prefer mouseleave for nested menus, or filter with event.relatedTarget.
relatedTarget is the element the pointer moved to. If it is still inside the bound element, you can ignore the event: if ($(event.relatedTarget).closest('#outer').length) return;
mouseout bubbles and re-fires on child boundary crossings. mouseleave fires only when the pointer exits the bound element entirely. For hover menus and tooltips with nested content, prefer mouseleave with mouseenter.
Call .trigger('mouseout') on the element. Use .triggerHandler('mouseout') to run handlers without bubbling.
Use .on('mouseout', handler). The .mouseout() shorthand is deprecated since jQuery 3.3. Unbind with .off('mouseout').

Next: .mouseout()

See the deprecated shorthand and how it maps 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.

10 people found this page helpful