JavaScript Element mouseout Event

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

What You’ll Learn

The mouseout event fires when a pointing device moves so the cursor is no longer inside the element or one of its children. Learn addEventListener vs onmouseout, bubbling vs mouseleave, the mouseover pair, relatedTarget, and five try-it labs.

01

Kind

Instance event

02

Type

MouseEvent

03

When

Leaves element / enters child

04

Handler

onmouseout

05

Bubbles?

Yes

06

Status

Baseline widely available

Introduction

mouseout answers: “Did the pointer leave this element’s content—or move into a child that covers it?” Because children obscure the parent, entering a child counts as leaving the parent for mouseout.

That is why MDN often prefers mouseleave for whole-component hover exit: mouseleave ignores descendant boundaries. mouseout is still useful when you want bubbling or per-child exit highlights.

💡
Beginner tip

Pair mouseout with mouseover (bubbling). Pair mouseleave with mouseenter (non-bubbling). Pick the pair that matches your hover model.

Understanding mouseout

An instance event that answers: “Did the pointer leave this target (including into a child)?”

  • Fires when the cursor leaves the element or enters a child that covers it.
  • Bubbles — can be listened for on a parent (delegation).
  • Descendants — moving among child boundaries fires more events.
  • Pairmouseover when the pointer enters.
  • Baseline Widely available on MDN (since July 2015).

📝 Syntax

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

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

onmouseout = (event) => { };

Event type

A MouseEvent (inherits from UIEvent and Event).

Handy properties

PropertyMeaning
targetThe element that was left (often a child when using delegation)
relatedTargetWhere the pointer is going (secondary target), if any
clientX / clientYPointer position in the viewport
currentTargetThe element whose listener is running (useful with bubbling)

⚖️ mouseout vs mouseleave

Featuremouseoutmouseleave
Bubbles?YesNo
Entering a childFires on the parent (child covers it)Does not fire on the parent
Moving among descendantsMany eventsQuiet until full exit
Best forDelegation / per-child exitWhole-component hover exit
Enter twinmouseovermouseenter
💡
MDN guidance

If you only care about entering/leaving a whole component, mouseenter / mouseleave are usually more sensible.

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("mouseout", fn)
Handler propertyel.onmouseout = fn
Enter pairmouseover
Non-bubbling exitmouseleave
Where did it go?event.relatedTarget
MDN statusBaseline Widely available

🔍 At a Glance

Four facts to remember about mouseout.

Event type
MouseEvent

UIEvent + Event

Means
left target

Or entered a child

Bubbles
true

Unlike mouseleave

Baseline
yes

Widely available

Examples Gallery

Examples follow MDN Element: mouseout event. Move the pointer among list items and in/out of containers.

📚 Getting Started

MDN mouseout vs mouseleave demo and the handler property.

Example 1 — List Items vs Whole List (MDN)

mouseout colors the item you left; mouseleave colors the whole ul.

JavaScript
const test = document.getElementById("test");

test.addEventListener("mouseleave", (event) => {
  event.target.style.color = "purple";
  setTimeout(() => {
    event.target.style.color = "";
  }, 1000);
});

test.addEventListener("mouseout", (event) => {
  event.target.style.color = "orange";
  setTimeout(() => {
    event.target.style.color = "";
  }, 500);
});
Try It Yourself

How It Works

List items obscure the ul, so mouseout targets children as you move among them.

Example 2 — onmouseout Property

Log when the pointer leaves the stage via the handler property.

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

stage.onmouseout = (event) => {
  out.textContent = "mouseout on " + event.target.tagName.toLowerCase();
};
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Counts, Destination & Delegation

Compare fire rates, read relatedTarget, and listen once on a parent.

Example 3 — Count mouseout vs mouseleave

Move among children, then leave the parent entirely.

JavaScript
const parent = document.getElementById("parent");
const out = document.getElementById("out");
let outCount = 0;
let leaveCount = 0;

parent.addEventListener("mouseout", () => {
  outCount++;
  render();
});

parent.addEventListener("mouseleave", () => {
  leaveCount++;
  render();
});

function render() {
  out.textContent = "mouseout=" + outCount + " mouseleave=" + leaveCount;
}
Try It Yourself

How It Works

mouseout fires while roaming children; mouseleave waits for a full exit.

Example 5 — Delegated mouseout Logging

One listener on the parent logs which child was left (bubbling).

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

list.addEventListener("mouseout", (event) => {
  if (event.target.tagName !== "LI") return;
  out.textContent = "left " + event.target.textContent;
});
Try It Yourself

How It Works

Because mouseout bubbles, one parent listener can observe exits from many children.

🚀 Common Use Cases

  • Highlight each list item as the pointer exits it (MDN-style).
  • Event delegation for dynamic child lists.
  • Debug hover paths with relatedTarget logs.
  • Legacy code that already uses onmouseout.
  • Teaching bubbling vs non-bubbling hover exit models.

🔧 How It Works

1

Pointer over target

Hotspot is inside an element or its painted children.

Inside
2

Leave boundary

Move outside, or into a child that covers the parent.

Edge
3

mouseout

Fires on the left target and bubbles upward.

Event
4

Handlers react

Style children, delegate from parents, or prefer mouseleave instead.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Bubbles; entering a child can fire mouseout on the parent.
  • For whole-component exit, prefer mouseleave.
  • Not typically fired when the element is removed/replaced (same family note as leave/out).
  • Related learning: mouseover, mouseleave, mouseenter, addEventListener(), JavaScript hub.

Browser Support

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

Baseline · Widely available

Element mouseout

Fires when the pointer leaves an element or enters a covering child; bubbles unlike mouseleave.

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
mouseout Baseline

Bottom line: Useful for delegation and per-child exits. Prefer mouseleave for quiet whole-component hover exit.

Conclusion

mouseout is the bubbling “left this target” signal—including when the pointer moves into a child. Use it for delegation and per-child exits; prefer mouseleave for whole-component hover cleanup.

Continue with mouseover, mouseleave, addEventListener(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use mouseout when you need bubbling / delegation
  • Check event.target carefully in parent listeners
  • Prefer mouseleave for whole-card hover exit
  • Pair with mouseover when you need the bubbling enter twin
  • Prefer addEventListener in production code

❌ Don’t

  • Expect quiet behavior while moving among children
  • Assume mouseout equals mouseleave
  • Forget that entering a child can fire parent mouseout
  • Build flicker-prone hover UI without filtering targets
  • Overwrite onmouseout if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about mouseout

Left the target—bubbling, child-aware exit.

5
Core concepts
📄02

Bubbles

unlike mouseleave

API
👆03

Child edges

more events

Why
🔄04

mouseover

enter twin

Pair
🎯05

Baseline

widely available

Status

❓ Frequently Asked Questions

It fires when a pointing device moves so the cursor is no longer contained within the element or one of its children. It also fires when the cursor enters a child element that covers the parent.
No. MDN marks Element mouseout 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 relatedTarget, clientX, clientY, and target.
mouseout bubbles and also fires when moving from a parent into a child (or among child boundaries). mouseleave does not bubble and fires only when leaving the element and all descendants.
For whole-component hover exit without descendant noise, MDN notes mouseenter/mouseleave are usually more sensible than mouseover/mouseout.
When you want bubbling/delegation, or when you care about leaving individual children (for example highlighting each list item as the pointer exits it).
Did you know?

MDN’s classic demo puts both listeners on one ul: mouseout paints individual li items orange, while mouseleave paints the whole list purple—proof that children obscure the parent for mouseout.

Next: mouseover

Learn the bubbling enter event and how it differs from mouseenter.

mouseover →

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