.hover() binds handlers for mouseenter and mouseleave in one call. With two functions it runs enter then leave; with one function (since 1.4) the same handler runs for both. Prefer .on in new code.
Syntax
Start with these common calls. Keep them short and readable.
.hover() registers under mouseenter and mouseleave.
There is no separate "hover" event name.
.off("mouseenter mouseleave") removes both.
Frequently Asked Questions
With two functions — .hover(handlerIn, handlerOut) — it binds mouseenter and mouseleave. With one function since 1.4 — .hover(handlerInOut) — the same function runs for both events. Both forms are deprecated since jQuery 3.3.
Yes. Prefer .on("mouseenter", handlerIn).on("mouseleave", handlerOut) for two handlers, or .on("mouseenter mouseleave", handlerInOut) for one. jQuery 3.x still runs .hover() for compatibility.
CSS :hover is stylesheet-only. .hover() runs JavaScript on enter/leave — useful for DOM changes and logic CSS cannot express. Prefer CSS for pure styling.
.hover() uses mouseenter/mouseleave, which do not re-fire when moving over child elements. mouseover bubbles and re-fires on child boundaries — often noisier for menus and highlights.
Use .off("mouseenter mouseleave") on the same elements. There is no separate "hover" event name — .hover() registers under mouseenter and mouseleave.
Replace .hover(fnIn, fnOut) with .on("mouseenter", fnIn).on("mouseleave", fnOut). Replace .hover(fn) with .on("mouseenter mouseleave", fn).