jQuery .mouseleave() Method

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

What You’ll Learn

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

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.

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.

📝 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:

1. Bind a handler — .mouseleave( handler ) (since 1.0, deprecated 3.3)

jQuery
.mouseleave( handler )
  • handler — function executed each time mouseleave fires: function( event ) { ... }.
  • Returns the jQuery object for chaining.
  • Modern replacement: .on( "mouseleave", handler ).

2. Bind with eventData — .mouseleave( [eventData], handler ) (since 1.4.3, deprecated 3.3)

jQuery
.mouseleave( [eventData], handler )
  • eventData — optional object available in the handler as event.data.
  • Modern replacement: .on( "mouseleave", eventData, handler ).

3. Trigger the event — .mouseleave() (since 1.0)

jQuery
.mouseleave()
  • No arguments — triggers mouseleave on every matched element.
  • Runs bound mouseleave handlers.
  • Preferred replacement: .trigger( "mouseleave" ).

Official jQuery API migration note

jQuery
// Deprecated binding
$( "#outer" ).mouseleave( function() {
  $( "#log" ).append( " Handler for `mouseleave` called. " );
} );

// Modern binding
$( "#outer" ).on( "mouseleave", function() {
  $( "#log" ).append( " Handler for `mouseleave` called. " );
} );

// Deprecated trigger
$( "#outer" ).mouseleave();

// Modern trigger
$( "#outer" ).trigger( "mouseleave" );

Return value

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

⚡ Quick Reference

GoalLegacy (.mouseleave)Modern replacement
Bind mouseleave handler$("#box").mouseleave(fn)$("#box").on("mouseleave", fn)
Pass data to handler$("#box").mouseleave({ action: "hide" }, fn)$("#box").on("mouseleave", { action: "hide" }, fn)
Pair enter and leave.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

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

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

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

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.

jQuery
var count = 0;

$( "#outer" ).mouseleave( function() {
  count++;
  $( "#log" ).text( "Outer handler fired (count: " + count + ")" );
} );

$( "#fire" ).click( function() {
  $( "#outer" ).mouseleave();
} );
Try It Yourself

How It Works

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

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.

jQuery
$( "#nav-item" )
  .mouseenter( function() {
    $( "#submenu" ).show();
    $( "#log" ).text( "Entered — submenu shown via .mouseenter()." );
  } )
  .mouseleave( function() {
    $( "#submenu" ).hide();
    $( "#log" ).text( "Left — submenu hidden via .mouseleave()." );
  } );
Try It Yourself

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

🚀 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).
  • Proxy triggers$("#btn").click(function(){ $("#panel").mouseleave(); }) — replace inner no-arg .mouseleave() with .trigger("mouseleave").
  • Shared eventData$(".tip").mouseleave({ action: "hide" }, fn) passes metadata without closures.
  • Hover pairs — chain .mouseenter(fnIn).mouseleave(fnOut) — same as deprecated .hover().
  • Automated testing — test suites may call .mouseleave() to simulate exit — consider .trigger("mouseleave") for explicit intent.

🧠 How .mouseleave() Routes Through jQuery

1

You call .mouseleave()

With a function argument, jQuery treats it as a bind request. With no arguments, it treats it as a trigger request.

dispatch
2

Bind path

.mouseleave(handler) delegates internally to .on("mouseleave", handler) — the handler is stored in jQuery’s event system.

.on("mouseleave")
3

Trigger path

No-arg .mouseleave() delegates to .trigger("mouseleave") — bound handlers run on each matched element.

.trigger("mouseleave")
4

jQuery object returned

Both paths return the original collection for chaining — .mouseleave(fn).hide() works the same as .on("mouseleave", fn).hide().

📝 Notes

  • Deprecated since jQuery 3.3 — do not use .mouseleave(handler) or .mouseleave(eventData, handler) in new code. Use .on("mouseleave") instead.
  • Bind with .mouseleave(handler) since jQuery 1.0; eventData form since 1.4.3.
  • No-argument .mouseleave() triggers the event since jQuery 1.0 — prefer .trigger("mouseleave").
  • .mouseleave() does not support event delegation — use .on("mouseleave", selector, fn) for dynamic menus.
  • Pair with .mouseenter() or .on("mouseenter") for complete hover — not mouseover / mouseout.
  • Remove handlers with .off("mouseleave") — not by calling .mouseleave(undefined).
  • Legacy code using .mouseleave() still runs in jQuery 3.x — migrate when you refactor those files.
  • For the full modern mouseleave guide — vs mouseout, hiding menus, and triggers — see the jQuery mouseleave event tutorial.

Browser Support

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

Bottom line: Safe in legacy jQuery projects. Migrate bindings to .on('mouseleave') and triggers to .trigger('mouseleave') when updating code.

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.

💡 Best Practices

✅ Do

  • Use .on("mouseleave", handler) for all new leave bindings
  • Pair with .on("mouseenter", handler) — not deprecated .hover()
  • Bind leave on the container that wraps menu + submenu together
  • Use .trigger("mouseleave") instead of no-arg .mouseleave()
  • Read the modern mouseleave event tutorial for delegation patterns

❌ Don’t

  • 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

Key Takeaways

Knowledge Unlocked

Six things to remember about .mouseleave()

Legacy bind, modern migrate.

6
Core concepts
data 02

eventData

Since 1.4.3

Handler
() 03

.mouseleave()

Trigger

No args
.on 04

.on("mouseleave")

Modern

Replace
05

.trigger()

Fire

Programmatic
3.3 06

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

Next: mousemove Event

Track pointer movement with event.pageX and event.pageY — essential for drag UIs.

mousemove 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