.mouseleave() is a shorthand for binding or triggering the mouseleave event (pointer leaves; children do not re-fire). With a handler it binds; with no arguments it triggers. Prefer .on / .trigger in new code.
Syntax
Start with these common calls. Keep them short and readable.
Learn the deprecated jQuery .mouseleave() shorthand: bind with .mouseleave(handler), pass eventData, trigger with no-arg .mouseleave(), and migrate to .on(\
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
.mouseleave() with no arguments fires the event — prefer .trigger("mouseleave").
jQuery
$("#target").mouseleave(function () {
console.log("Handler for mouseleave called.");
});
$("#fire").click(function () {
$("#target").mouseleave(); // same idea as .trigger("mouseleave")
});
With a handler — .mouseleave(handler) or .mouseleave(eventData, handler) — it binds a callback that runs when the pointer leaves the element. With no arguments — .mouseleave() — it triggers mouseleave on each matched element. Binding forms are deprecated since jQuery 3.3.
Yes. Prefer .on("mouseleave", handler) or .on("mouseleave", eventData, handler) to bind, and .trigger("mouseleave") to fire. jQuery 3.x still runs .mouseleave() for compatibility.
.mouseleave(handler) only registers a callback. .mouseleave() with no arguments triggers the event (same idea as .trigger("mouseleave")).
Replace .mouseleave(fn) with .on("mouseleave", fn). Replace .mouseleave(data, fn) with .on("mouseleave", data, fn). Replace no-arg .mouseleave() with .trigger("mouseleave").
mouseleave does not re-fire when the pointer leaves a child. mouseout does. Prefer mouseleave for parent hover cleanup with nested content.
Since 1.4.3 you can pass data before the handler. It appears as event.data inside the callback. Modern form: .on("mouseleave", eventData, handler).