jQuery .hover() Method

Beginner
6 min read
Updated: Oct 2026
5 examples
Live preview

What Is the .hover() Method?

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

Remember
$("#box").hover(fnIn, fnOut)   // deprecated
$("#box").hover(fnInOut)       // deprecated (1.4+)

// Modern:
$("#box").on("mouseenter", fnIn).on("mouseleave", fnOut)
$("#box").on("mouseenter mouseleave", fnInOut)
FormMeansPrefer
.hover(fnIn, fnOut)Enter + leave.on("mouseenter", fnIn).on("mouseleave", fnOut)
.hover(fn)Same fn both.on("mouseenter mouseleave", fn)
Unbind—.off("mouseenter mouseleave")

How to Use .hover()

Know the two signatures, then map them to .on.

  1. Select element(s): $("li"), $("#box"), etc.
  2. Two handlers (legacy): .hover(fnIn, fnOut).
  3. One handler (legacy, 1.4+): .hover(fn) — check event.type if needed.
  4. Unbind with .off("mouseenter mouseleave").
PieceRequired?Role
handlerInTwo-arg formRuns on mouseenter
handlerOutTwo-arg formRuns on mouseleave
handlerInOutOne-arg formRuns on enter and leave
Return value—jQuery set (chainable)

Pseudocode

Pseudocode
function hover(element, fnIn, fnOut?):
    if fnOut given:
        on mouseenter → fnIn
        on mouseleave → fnOut
    else:
        on mouseenter → fnIn
        on mouseleave → fnIn   // same function

// Prefer naming events with .on("mouseenter") / .on("mouseleave")

Cheat Sheet

Quick map from shorthand to modern calls.

LegacyModern
.hover(fnIn, fnOut).on("mouseenter", fnIn).on("mouseleave", fnOut)
.hover(fn).on("mouseenter mouseleave", fn)
Unbind.off("mouseenter mouseleave")
Added1.0 (one-arg form 1.4)
StatusDeprecated 3.3+

Live Preview

Run presets that show two-handler hover, single-handler, unbind, and migration (simulated with mouseenter / mouseleave triggers).

Legacy demos for reading old code — prefer .on("mouseenter") / .on("mouseleave") in new projects.

Result
enter
leave

jQuery Examples

Short snippets for legacy .hover(). Prefer the modern forms in new work — use Try It Yourself to experiment.

Example 1 — .hover(fnIn, fnOut)

Official style: enter appends a marker; leave removes it.

jQuery
$("li").hover(
  function () {
    $(this).append(" ***");
  },
  function () {
    $(this).text($(this).text().replace(" ***", ""));
  }
);
Try It Yourself

How It Works

  1. fnIn runs on mouseenter — appends ***.
  2. fnOut runs on mouseleave — removes the marker.
  3. Same as separate mouseenter / mouseleave binds.
  4. Children inside the li do not re-trigger enter/leave.

Example 2 — Mark a Cell on Enter

Official “highlight” idea, CSS-free: prefix text while hovered.

jQuery
$("td").hover(
  function () {
    $(this).data("label", $(this).text());
    $(this).text("[*] " + $(this).data("label"));
  },
  function () {
    $(this).text($(this).data("label"));
  }
);
Try It Yourself

How It Works

  1. Enter stores the original text, then prefixes [*].
  2. Leave restores the saved label.
  3. No CSS required — pure text feedback.
  4. Modern: same logic with .on("mouseenter") / .on("mouseleave").

Example 3 — Unbind with .off()

Official cleanup: remove enter/leave handlers by those event names.

jQuery
$("td").hover(fnIn, fnOut);

$("#remove").on("click", function () {
  $("td").off("mouseenter mouseleave");
});
Try It Yourself

How It Works

  1. .hover() registers under mouseenter and mouseleave.
  2. There is no separate "hover" event name.
  3. .off("mouseenter mouseleave") removes both.
  4. After off, enter/leave no longer run your handlers.

Example 4 — Single Handler .hover(fn)

One function for enter and leave (since 1.4) — good for toggles.

jQuery
$("li.item").hover(function () {
  $(this).next(".detail").toggle();
});
Try It Yourself

How It Works

  1. One function is bound to both enter and leave.
  2. toggle() runs twice per hover cycle — show then hide.
  3. event.type is mouseenter or mouseleave if you need a branch.
  4. Modern: .on("mouseenter mouseleave", fn).

Example 5 — Migrate to .on

Side-by-side: same enter/leave, recommended API.

jQuery
// Legacy
$("#legacy").hover(
  function () { console.log("enter (legacy)"); },
  function () { console.log("leave (legacy)"); }
);

// Modern (use this)
$("#modern")
  .on("mouseenter", function () { console.log("enter"); })
  .on("mouseleave", function () { console.log("leave"); });
Try It Yourself

How It Works

  1. Both listen for the same enter/leave events.
  2. .hover(fnIn, fnOut) is a thin wrapper around two .on calls.
  3. .on is not deprecated and supports delegation.
  4. New projects should only use .on / .off.

Edge Cases & Pitfalls

Common traps when reading or writing .hover() code.

deprecated

Do not use in new code

Both signatures are deprecated since 3.3. Teach and write .on("mouseenter") / .on("mouseleave").

unbind

No "hover" event name

Clean up with .off("mouseenter mouseleave"), not .off("hover").

vs over

Not the same as mouseover

mouseover/mouseout bubble through children. Enter/leave usually match “hover this box” better.

css

Prefer CSS for pure style

Colors and simple highlights belong in :hover. Use JS when you need DOM or logic changes.

touch

Limited on touch devices

There is no true hover on many phones. Don’t rely on hover-only UI for critical actions.

Browser Support

.hover() has existed since jQuery 1.0 (one-arg form since 1.4). It still runs in jQuery 3.x browsers, but is deprecated since 3.3 — prefer .on("mouseenter") / .on("mouseleave").

✓ Deprecated 3.3+

.hover() shorthand

Works wherever jQuery event APIs work in the browser. Use on/off for new code.

100% Browser support
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
.hover() (legacy) Excellent (deprecated)

Bottom line: Migrate: .hover(fnIn, fnOut) → .on("mouseenter", fnIn).on("mouseleave", fnOut).

Performance Notes

ApproachCostNote
.hover(fnIn, fnOut)Same as two .onThin wrapper — no win
Many direct bindsHigher memoryPrefer delegated .on on a parent
CSS :hoverCheapest for styleUse when no JS logic is needed

Switching to .on does not slow you down — it clarifies intent and unlocks delegation. Keep enter/leave handlers light.

Key Takeaways

  • Deprecated: .hover() since jQuery 3.3.
  • Meaning: shorthand for mouseenter + mouseleave.
  • Modern: .on("mouseenter", …).on("mouseleave", …).
  • Unbind: .off("mouseenter mouseleave") — not "hover".

One line: .hover() is a deprecated enter/leave shorthand — prefer .on("mouseenter") and .on("mouseleave").

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

Next: mousedown event

Fire when the mouse button is pressed — before release.

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

8 people found this page helpful