jQuery mouseleave Event — Leave Without Child Bubbling

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

Definition

mouseleave fires when the pointer leaves the element it is bound to. Leaving a child does not fire it (unlike mouseout). Bind with .on("mouseleave", handler) (jQuery 1.7+).

Syntax

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

jQuery
$("#outer").on("mouseleave", function () { ... })
$("#outer").trigger("mouseleave")

// Leave element → fires once
// Leave a child but stay inside element → does NOT fire
// Prefer on/trigger — not the deprecated .mouseleave()
CallWhat it does
mouseleaveLearn the jQuery mouseleave event: bind with .on(\

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

Parameters

ParameterDescription
Step 1Select the element(s): $("#outer"), $(".card"), etc.
Step 2Bind: .on("mouseleave", function (event) { ... }).
Step 3Pair with .on("mouseenter", …) for hover-style UI.

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 a mouseleave Handler

Official style: .on("mouseleave", …) on a container.

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

How It Works

  1. Select #outer.
  2. Bind with .on("mouseleave", handler).
  3. Pointer leaves the element entirely.

Example 2 — Trigger mouseleave from Code

Fire the same handlers with a click on another control.

jQuery
$("#outer").on("mouseleave", function () {
  console.log("Handler for mouseleave called.");
});

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

How It Works

  1. Bind the real handler on #outer.
  2. Another control listens for click.
  3. trigger("mouseleave") runs #outer’s handlers.

Example 3 — mouseleave vs mouseout

Leaving a child re-fires mouseout, not mouseleave.

jQuery
var leaveCount = 0;
var outCount = 0;

$("#leaveBox").on("mouseleave", function () {
  leaveCount += 1;
  console.log("mouseleave:", leaveCount);
});

$("#outBox").on("mouseout", function () {
  outCount += 1;
  console.log("mouseout:", outCount);
});
// Leave each box entirely, and also leave Inner while staying in the box:
// mouseleave stays 1 for full leave; mouseout increases on Inner too.
Try It Yourself

How It Works

  1. mouseleave counts only leaving the bound box.
  2. mouseout also fires when you leave the Inner child.
  3. Choose mouseleave for stable hover cleanup on parents with children.

Frequently Asked Questions

mouseleave fires when the pointer leaves the bound element. Unlike mouseout, moving out of a child into another part of the same parent does not fire it. Bind with .on("mouseleave", handler) (jQuery 1.7+). jQuery simulates the event across browsers.
Prefer .on("mouseleave", handler). The .mouseleave(handler) shorthand is deprecated since jQuery 3.3. To fire the event, use .trigger("mouseleave") instead of .mouseleave().
mouseout bubbles and also fires when the pointer leaves a child for another descendant or the parent. mouseleave does not — it fires only when leaving the element it is bound to, not when leaving a descendant.
Use mouseenter for when the pointer enters the element (same non-child-bubbling behavior). .hover(enterFn, leaveFn) is a convenience that wires both.
Call $(selector).trigger("mouseleave"). That runs bound handlers without needing a real pointer move.
No — that is the point versus mouseout. Leaving a child does not trigger a mouseleave handler bound only on the parent.

Next: .mouseleave() Method — Deprecated Shorthand

See the deprecated method form — then keep using .on / .trigger.

.mouseleave() 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.

8 people found this page helpful