jQuery mouseout Event

Beginner
5 min read
Updated: Nov 2026
3 examples
Mouse Events

Definition

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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("#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
CallWhat it does
mouseoutLearn the jQuery mouseout event: bind with .on('mouseout'), understand bubbling vs mouseleave, filter with event.relatedTarget, trigger handlers, examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the element that should react when the pointer leaves.
Step 2Bind with .on("mouseout", handler).
Step 3If children exist, check event.relatedTarget — or switch to mouseleave.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

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.

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.

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.

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() Method — Deprecated Shorthand

See the deprecated shorthand and how it maps to .on("mouseout").

.mouseout() Method — Deprecated Shorthand tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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