The .mouseleave() method is jQuery’s legacy shorthand for binding and triggering the mouseleave event. This tutorial covers .mouseleave(handler) since 1.0, .mouseleave(eventData, handler) since 1.4.3, no-argument .mouseleave() as a trigger, migration to .on("mouseleave") and .trigger("mouseleave"), and why the binding form is deprecated since jQuery 3.3. For the modern mouseleave event API, see the jQuery mouseleave event tutorial.
01
.mouseleave(fn)
Bind handler
02
eventData
Since 1.4.3
03
.mouseleave()
Trigger event
04
.on()
Modern bind
05
.trigger()
Modern fire
06
Deprecated
Since 3.3
Fundamentals
Introduction
Before jQuery 1.7 unified events with .on() and .off(), every common event had a matching shorthand — .click(), .mouseleave(), .keydown(), and dozens more. The .mouseleave() method let you bind a hover-exit handler in one short call: $("#menu").mouseleave(function(){ ... }). It remains in jQuery 3.x for backward compatibility but is marked deprecated.
Understanding .mouseleave() matters when reading older dropdown menus, tooltip plugins, and legacy tutorials. The method does two distinct jobs: with a function argument it binds; with no arguments it triggers. Modern jQuery splits those roles explicitly — .on("mouseleave", handler) for binding and .trigger("mouseleave") for firing. This page documents the shorthand API and shows how to migrate.
Concept
Understanding the .mouseleave() Method
The official jQuery API describes .mouseleave() as a way to bind an event handler to the mouseleave event, or trigger that event on an element. When you pass a handler, jQuery registers it on each matched element and calls it when the pointer leaves that element entirely — without firing when moving among nested children, unlike mouseout.
When you call .mouseleave() with no arguments, jQuery synthetically fires the mouseleave event on each matched element. Bound handlers run immediately. This trigger behavior is equivalent to .trigger("mouseleave").
⚠️
Deprecated since jQuery 3.3
Do not use .mouseleave(handler) or .mouseleave(eventData, handler) in new code. Replace them with .on("mouseleave", handler) or .on("mouseleave", eventData, handler). Replace no-argument .mouseleave() with .trigger("mouseleave"). For comparison with mouseout, hiding menus, and pairing with mouseenter, read the jQuery mouseleave event tutorial.
Foundation
📝 Syntax
The .mouseleave() method has three signatures from the official jQuery API. The binding forms are deprecated; the trigger form remains valid but .trigger("mouseleave") is preferred:
.on("mouseenter", show).on("mouseleave", hide) — not via single .mouseleave()
Trigger mouseleave programmatically
$("#outer").mouseleave()
$("#outer").trigger("mouseleave")
Remove mouseleave handlers
$("#box").off("mouseleave")
Delegated mouseleave on children
$("#menu").on("mouseleave", "li", fn) — not available via .mouseleave()
Both enter + leave (legacy)
.hover(fnIn, fnOut) — also deprecated; fnOut maps to mouseleave
Compare
📋 .mouseleave() vs .on("mouseleave") vs .trigger("mouseleave") vs .hover()
Four related APIs — know which one binds, which one fires, and which one covers both enter and leave.
.mouseleave()
deprecated
Legacy bind (.mouseleave(fn)) or trigger (.mouseleave()) — use modern APIs for new code
.on("mouseleave")
bind
Modern binding since 1.7 — supports eventData and delegation on dynamic menus
.trigger("mouseleave")
fire
Programmatically run handlers — clearer than no-arg .mouseleave()
.hover()
enter+leave
Deprecated shorthand — handlerOut is the mouseleave callback
Hands-On
Examples Gallery
Five examples cover binding, eventData, triggering, migration from .mouseleave() to .on("mouseleave"), and legacy hide-on-leave menus. Use the Try-it links to run each snippet in the browser. Remember: binding with .mouseleave(handler) is deprecated — these demos show legacy syntax you will encounter in older code.
📚 Binding & Triggering
Legacy .mouseleave() signatures for binding handlers and firing events programmatically.
Example 1 — Bind Handler with .mouseleave(handler)
The canonical legacy pattern — attach a function that runs when the pointer leaves the element entirely.
jQuery
$( "#outer" ).mouseleave( function() {
$( "#log" ).append( " Handler ran via .mouseleave(function(){ ... }). " );
} );
Pointer leaves #outer entirely → log appends handler message
Moving into Inner child inside #outer → handler does NOT fire
Deprecated — prefer .on("mouseleave", fn) for new code
How It Works
.mouseleave(fn) registers the function on the element. jQuery internally routes this to .on("mouseleave", fn). The handler runs once when the pointer exits the outer boundary.
Example 2 — Pass eventData with .mouseleave(eventData, handler)
Since jQuery 1.4.3, pass an object before the handler — it arrives as event.data.
jQuery
$( ".tooltip" ).mouseleave( { action: "hide" }, function( event ) {
var id = $( this ).data( "id" );
$( "#log" ).text(
"Hide: " + id + " | eventData.action: " + event.data.action
);
} );
Leave Help A → "Hide: help-a | eventData.action: hide"
Leave Help B → "Hide: help-b | eventData.action: hide"
Same handler, shared eventData on every .tooltip trigger
How It Works
jQuery stores the { action: "hide" } object and injects it into event.data when any matched tooltip trigger is left. Modern equivalent: .on("mouseleave", { action: "hide" }, fn).
Example 3 — Trigger mouseleave with No-Argument .mouseleave()
Calling .mouseleave() without a handler fires the mouseleave event programmatically.
The first .mouseleave(function(){ ... }) binds a handler on #outer. The second binds on #fire and calls $("#outer").mouseleave() with no arguments — that synthetically fires mouseleave. Replace with $("#outer").trigger("mouseleave") for clarity.
📈 Migration & Hide on Leave
Compare legacy and modern APIs, and hide UI with legacy shorthand methods.
Example 4 — Migration: .mouseleave(fn) vs .on("mouseleave", fn)
Both bind the same mouseleave event — .on() is the recommended API for new code.
jQuery
$( "#legacy" ).mouseleave( function() {
$( "#log" ).text( "Legacy: .mouseleave(function(){ ... }) — deprecated since jQuery 3.3." );
} );
$( "#modern" ).on( "mouseleave", function() {
$( "#log" ).text( "Modern: .on('mouseleave', function(){ ... }) — use this for new code." );
} );
Leave #legacy → legacy deprecation message
Leave #modern → modern .on("mouseleave") message
Behavior is identical — only the API name differs
How It Works
Under the hood, .mouseleave(fn) calls .on("mouseleave", fn). Migration is a straight rename with no behavior change for simple bindings. The advantage of .on() is delegation — $("#menu").on("mouseleave", "li", fn) — which .mouseleave() cannot do.
Example 5 — Legacy Hide Submenu with .mouseenter() + .mouseleave()
Show on enter, hide on leave — the exit half of deprecated .hover(fnIn, fnOut), using legacy shorthand methods.
Enter #nav-item → submenu shows (.mouseenter)
Leave #nav-item entirely → submenu hides (.mouseleave)
Migrate to .on("mouseenter") / .on("mouseleave") in new code
How It Works
This is the classic legacy dropdown pattern. .mouseleave(fn) is the exit callback — the same role as the second argument to deprecated .hover(fnIn, fnOut). Both shorthand methods are deprecated — migrate to .on("mouseenter", fn).on("mouseleave", fn).
Applications
🚀 Common Use Cases
Reading legacy code — recognize $("#menu").mouseleave(fn) as equivalent to .on("mouseleave", fn) in older dropdown plugins.
Close dropdowns — legacy code uses .mouseleave(fn) to hide submenus — migrate to .on("mouseleave", fn).
jQuery simulates the mouseleave event in every browser it supports. The .mouseleave() method itself is a jQuery API — it works in jQuery 1.x, 2.x, and 3.x. Binding via .mouseleave(handler) is deprecated since 3.3 but still functional; triggering via no-arg .mouseleave() also remains supported.
✓ jQuery 1.0+
jQuery .mouseleave() method
Supported across all jQuery versions you are likely to maintain. Deprecated binding since 3.3 — use .on('mouseleave') for new projects. Native equivalent for binding: element.addEventListener('mouseleave', fn).
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
.mouseleave()Legacy API
Bottom line: Safe in legacy jQuery projects. Migrate bindings to .on('mouseleave') and triggers to .trigger('mouseleave') when updating code.
Wrap Up
Conclusion
The jQuery .mouseleave() method is the legacy shorthand for binding and triggering mouseleave handlers. Use .mouseleave(handler) or .mouseleave(eventData, handler) to bind — both deprecated since jQuery 3.3. Use no-argument .mouseleave() to trigger — equivalent to .trigger("mouseleave").
For new code, prefer .on("mouseleave", fn) for binding and .trigger("mouseleave") for programmatic firing. When you encounter .mouseleave() in older projects, recognize it, understand it, and migrate when practical. For comparison with mouseout, hiding menus, and pairing with mouseenter, continue with the jQuery mouseleave event tutorial.
Write new code with deprecated .mouseleave(handler)
Swap mouseleave for mouseout on containers with nested submenus
Bind leave only on the menu label — not the wrapper that includes the submenu
Confuse .mouseleave(fn) (bind) with .mouseleave() (trigger)
Copy deprecated patterns from old tutorials without modernizing them
Summary
Key Takeaways
Knowledge Unlocked
Six things to remember about .mouseleave()
Legacy bind, modern migrate.
6
Core concepts
.ml01
.mouseleave(fn)
Bind
Deprecated
data02
eventData
Since 1.4.3
Handler
()03
.mouseleave()
Trigger
No args
.on04
.on("mouseleave")
Modern
Replace
⚡05
.trigger()
Fire
Programmatic
3.306
Deprecated
Since 3.3
Migrate
❓ Frequently Asked Questions
The .mouseleave() method has two roles. With a handler argument — .mouseleave(handler) or .mouseleave(eventData, handler) — it binds a function that runs when the pointer leaves the matched element entirely. With no arguments — .mouseleave() — it triggers the mouseleave event on each matched element, running bound handlers. Both forms have been part of jQuery since 1.0; the binding form is deprecated since 3.3.
Yes — the binding signatures .mouseleave(handler) and .mouseleave(eventData, handler) are deprecated since jQuery 3.3. Use .on('mouseleave', handler) or .on('mouseleave', eventData, handler) instead. The no-argument .mouseleave() trigger form still works but .trigger('mouseleave') is clearer and preferred in modern code. Existing legacy code continues to run in jQuery 3.x; migrate when you touch those files.
.mouseleave(handler) registers a callback — it does not fire the event immediately. .mouseleave() with no arguments triggers the mouseleave event programmatically on every matched element, the same as .trigger('mouseleave'). The handler form is deprecated for binding; the no-arg form is a trigger shorthand. Always check whether parentheses contain a function before reading legacy jQuery code.
Replace .mouseleave(fn) with .on('mouseleave', fn). Replace .mouseleave(data, fn) with .on('mouseleave', data, fn). Replace no-arg .mouseleave() with .trigger('mouseleave'). Replace .unbind('mouseleave') cleanup with .off('mouseleave'). Under the hood, .mouseleave(handler) already delegates to .on('mouseleave') — migration is a straight rename with no behavior change for simple bindings.
Yes. jQuery 3.x keeps .mouseleave() for backward compatibility with jQuery 1.x and 2.x codebases. It still binds and triggers correctly. The API docs mark it deprecated to steer new projects toward .on() and .trigger(). Do not use .mouseleave(handler) in new code — prefer the modern API covered in the jQuery mouseleave event tutorial.
Since jQuery 1.4.3, you can pass an object as the first argument before the handler. jQuery attaches it to event.data inside the callback — for example, .mouseleave({ action: 'hide' }, fn) lets fn read event.data.action. This avoids closures when the same handler serves multiple elements. The modern equivalent is .on('mouseleave', { action: 'hide' }, fn).
Did you know?
In deprecated .hover(handlerIn, handlerOut), the second argument handlerOut is literally a mouseleave handler — jQuery never created a separate "hover" browser event. When you see legacy code like $("#nav").hover(showMenu, hideMenu), recognize that hideMenu runs on mouseleave. Migrating means .on("mouseenter", showMenu).on("mouseleave", hideMenu) — or renaming individual .mouseleave(fn) calls to .on("mouseleave", fn).