JavaScript Element mouseenter Event

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
DOM event
Instance event

What You’ll Learn

The mouseenter event fires when a pointing device moves into an element. Learn addEventListener vs onmouseenter, how it differs from mouseover, the mouseleave pair, CSS :hover-like patterns, and five try-it labs.

01

Kind

Instance event

02

Type

MouseEvent

03

When

Pointer enters

04

Handler

onmouseenter

05

Bubbles?

No

06

Status

Baseline widely available

Introduction

mouseenter answers: “Did the pointer just move into this element’s content area?” Pair it with mouseleave and you get JS hover enter/exit signals similar to CSS :hover.

Unlike mouseover, mouseenter does not bubble and does not keep firing while you move among the element’s descendants. That makes it friendlier for card/hover UI where you only care about entering the whole component once.

💡
Beginner tip

“Entering” follows the DOM tree, not only the painted box. A child positioned outside its parent can still cause mouseenter on the parent when the pointer enters that child.

Understanding mouseenter

An instance event that answers: “Did the pointer just enter this element?”

  • Fires when the pointer hotspot first moves into the element.
  • Does not bubble — stays on the element that was entered.
  • Descendants — moving among children does not re-fire on the parent.
  • Pairmouseleave when the pointer exits.
  • Baseline Widely available on MDN (since July 2015).

📝 Syntax

Use the event name with addEventListener, or set the handler property:

JavaScript
addEventListener("mouseenter", (event) => { });

onmouseenter = (event) => { };

Event type

A MouseEvent (inherits from UIEvent and Event).

Handy properties

PropertyMeaning
clientX / clientYPointer position in the viewport
relatedTargetThe secondary target (where the pointer came from), if any
targetThe element that was entered
ctrlKey / shiftKey / …Modifier keys at enter time

⚖️ mouseenter vs mouseover

Featuremouseentermouseover
Bubbles?NoYes
Moving among descendantsDoes not re-fire on the parentFires / bubbles as you move
Best forWhole-component hover enterDelegation / deep trees (sometimes)
Exit twinmouseleavemouseout
⚠️
Performance note (MDN)

In deep hierarchies, entering can send many mouseenter events (one per ancestor). If that becomes costly, prefer listening for mouseover instead.

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("mouseenter", fn)
Handler propertyel.onmouseenter = fn
Exit pairmouseleave
CSS cousin:hover
Bubbling twinmouseover / mouseout
MDN statusBaseline Widely available

🔍 At a Glance

Four facts to remember about mouseenter.

Event type
MouseEvent

UIEvent + Event

Means
entered

Pointer moved in

Bubbles
false

Unlike mouseover

Baseline
yes

Widely available

Examples Gallery

Examples follow MDN Element: mouseenter event. Move the pointer into and out of the stage elements.

📚 Getting Started

MDN-style enter/leave logging and the handler property.

Example 1 — Border Highlight + Enter Count (MDN)

Change the border on enter and restore it on leave; log each event.

JavaScript
let enterEventCount = 0;
let leaveEventCount = 0;
const mouseTarget = document.getElementById("mouseTarget");
const unorderedList = document.getElementById("unorderedList");

mouseTarget.addEventListener("mouseenter", () => {
  mouseTarget.style.border = "5px dotted orange";
  enterEventCount++;
  addListItem(`This is mouseenter event ${enterEventCount}.`);
});

mouseTarget.addEventListener("mouseleave", () => {
  mouseTarget.style.border = "1px solid #333333";
  leaveEventCount++;
  addListItem(`This is mouseleave event ${leaveEventCount}.`);
});

function addListItem(text) {
  const li = document.createElement("li");
  li.textContent = text;
  unorderedList.appendChild(li);
}
Try It Yourself

How It Works

Enter once to highlight; leave to restore. Children inside do not spam extra enters on the parent.

Example 2 — onmouseenter Property

Use the handler property form to flip a class.

JavaScript
const card = document.getElementById("card");
const out = document.getElementById("out");

card.onmouseenter = () => {
  card.classList.add("is-hot");
  out.textContent = "entered";
};

card.onmouseleave = () => {
  card.classList.remove("is-hot");
  out.textContent = "left";
};
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Compare, Hover & Nesting

Count mouseenter vs mouseover, build a hover card, and watch nested children.

Example 3 — Count mouseenter vs mouseover

Move among children and compare how often each event fires on the parent.

JavaScript
const parent = document.getElementById("parent");
const out = document.getElementById("out");
let enterCount = 0;
let overCount = 0;

parent.addEventListener("mouseenter", () => {
  enterCount++;
  render();
});

parent.addEventListener("mouseover", () => {
  overCount++;
  render();
});

function render() {
  out.textContent = "mouseenter=" + enterCount + " mouseover=" + overCount;
}
Try It Yourself

How It Works

mouseover keeps firing as you move among descendants; mouseenter usually stays at 1 until you fully leave.

Example 4 — Hover Card Preview

Show a tip when the pointer enters the card; hide it on leave.

JavaScript
const card = document.getElementById("card");
const tip = document.getElementById("tip");

card.addEventListener("mouseenter", () => {
  tip.hidden = false;
  tip.textContent = "Preview details…";
});

card.addEventListener("mouseleave", () => {
  tip.hidden = true;
});
Try It Yourself

How It Works

Because mouseenter ignores child moves, the tip stays stable while the pointer travels inside the card.

Example 5 — Nested Boxes Still Count as Enter

Entering a child still means you entered the parent’s DOM subtree.

JavaScript
const outer = document.getElementById("outer");
const out = document.getElementById("out");

outer.addEventListener("mouseenter", (event) => {
  out.textContent =
    "entered outer (from " +
    ((event.relatedTarget && event.relatedTarget.id) || "outside") +
    ")";
});

outer.addEventListener("mouseleave", () => {
  out.textContent = "left outer";
});
Try It Yourself

How It Works

relatedTarget can tell you where the pointer came from when the engine provides it.

🚀 Common Use Cases

  • Card / tile hover previews that should not flicker among children.
  • Highlight a whole component when the pointer enters (JS version of :hover).
  • Start prefetch or analytics when a user hovers a product row.
  • Show tooltips tied to an entire control, not each inner span.
  • Teach the difference between bubbling mouseover and non-bubbling enter.

🔧 How It Works

1

Pointer outside

No enter relationship with the element yet.

Idle
2

mouseenter

Hotspot moves into the element’s DOM content area.

Enter
3

Move among children

Parent does not get another mouseenter.

Stable
4

mouseleave

Pointer exits the element—clean up hover UI.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Does not bubble; use mouseover when you need delegation from a parent.
  • Deep trees can fire many enter events on ancestors—watch performance.
  • For touch UIs, hover enter/leave is not always available; design a non-hover path too.
  • Related learning: mousedown, click, addEventListener(), JavaScript hub.

Browser Support

mouseenter is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. Non-bubbling enter/leave behavior is consistent across modern engines.

Baseline · Widely available

Element mouseenter

Fires when the pointer enters an element; pair with mouseleave for hover UI.

Full Widely available
Google Chrome Full support
Yes
Mozilla Firefox Full support
Yes
Apple Safari Full support
Yes
Microsoft Edge Full support
Yes
Opera Full support
Yes
Internet Explorer Supported
Yes
mouseenter Baseline

Bottom line: Great for component hover enter. Prefer mouseover for deep-tree delegation or performance-sensitive cases.

Conclusion

mouseenter is the non-bubbling “pointer entered this element” signal. Pair it with mouseleave for stable hover UI, and reach for mouseover when bubbling or deep-tree performance matters.

Continue with mouseleave, mousedown, click, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use mouseenter / mouseleave for whole-component hover
  • Prefer CSS :hover when you only need visual changes
  • Provide a non-hover path for touch / keyboard users
  • Use mouseover when you need bubbling / delegation
  • Prefer addEventListener in production code

❌ Don’t

  • Expect mouseenter to bubble like mouseover
  • Attach enter listeners to every ancestor in a huge DOM without measuring cost
  • Assume hover UX works the same on phones
  • Forget the exit twin (mouseleave) when cleaning up UI
  • Overwrite onmouseenter if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about mouseenter

Pointer entered—non-bubbling hover start.

5
Core concepts
📄02

No bubble

unlike mouseover

API
👆03

Stable hover

kids do not re-fire

Why
🔄04

mouseleave

exit pair

Pair
🎯05

Baseline

widely available

Status

❓ Frequently Asked Questions

It fires when a pointing device moves so its hotspot enters the element. Combined with mouseleave, it behaves a lot like CSS :hover for that element.
No. MDN marks Element mouseenter as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
A MouseEvent (inherits from UIEvent and Event). Useful fields include clientX, clientY, relatedTarget, and modifier keys.
mouseenter does not bubble and is not sent again when the pointer moves between the element and its descendants. mouseover bubbles and fires when moving among descendants.
It follows the element’s position in the DOM tree. If a child is visually outside its parent, entering the child can still fire mouseenter on the parent.
In very deep hierarchies, listening for mouseenter on many ancestors can fire a large number of events. MDN notes that mouseover can be a better choice in those performance-sensitive cases.
Did you know?

MDN compares mouseenter + mouseleave to CSS :hover: enter when the pointer arrives, leave when it exits the element’s content area—without the descendant churn of mouseover.

Next: mouseleave

Learn the non-bubbling event that fires when the pointer leaves an element.

mouseleave →

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.

5 people found this page helpful