JavaScript Element mouseup Event

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

What You’ll Learn

The mouseup event fires when a pointing-device button is released inside an element. Learn addEventListener vs onmouseup, button / buttons, how it differs from mousedown, click, and pointerup, drag-end patterns, and five try-it labs.

01

Kind

Instance event

02

Type

MouseEvent

03

When

Button released

04

Handler

onmouseup

05

Pair

mousedown

06

Status

Baseline widely available

Introduction

mouseup answers: “Did the user just release a pointing-device button while the pointer was over this element?” It is the counterpoint to mousedown.

A completed left-click usually runs mousedownmouseupclick. Use mouseup to end a press, finish a drag, or clear pressed styles. Prefer click for primary UI actions so keyboard users are included.

💡
Beginner tip

With a physical mouse, mouseup fires whenever any button is released. pointerup fires only for the last button release while others were still held.

Understanding mouseup

An instance event that answers: “Was a pointing-device button just released here?”

  • Fires when a button is released while the pointer is inside the element.
  • MouseEventbutton, buttons, coordinates, modifiers.
  • Handleronmouseup or addEventListener("mouseup", ...).
  • Order — usually after mousedown and before (if completed) click.
  • Baseline Widely available on MDN (since July 2015).

📝 Syntax

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

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

onmouseup = (event) => { };

Event type

A MouseEvent (inherits from UIEvent and Event).

Handy properties

PropertyMeaning
buttonWhich button changed: 0 primary, 1 auxiliary (middle), 2 secondary (right)
buttonsBitmask of buttons still held after this release
clientX / clientYPointer position in the viewport
ctrlKey / shiftKey / altKey / metaKeyModifier keys at release time

⚡ When mouseup Fires

  • A pointing-device button is released while the pointer is inside the element.
  • Any mouse button can produce it (primary, middle, secondary)—check event.button.
  • It fires on release; the earlier press was a separate mousedown event.

A typical completed left-click sequence is: mousedownmouseupclick.

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("mouseup", fn)
Handler propertyel.onmouseup = fn
Which buttonevent.button (0 / 1 / 2)
Positionevent.clientX, event.clientY
End a dragOften listen on window so release outside still ends it
Primary actionsPrefer click for accessibility
MDN statusBaseline Widely available

🔍 At a Glance

Four facts to remember about mouseup.

Event type
MouseEvent

UIEvent + Event

Means
button up

Release, not press

Key field
button

0 · 1 · 2

Baseline
yes

Widely available

Examples Gallery

Examples follow MDN Element: mouseup event. Press and release a mouse button on the stage elements to trigger events.

📚 Getting Started

Listener patterns and the onmouseup property.

Example 1 — Log Release Position

Show viewport coordinates when the button goes up.

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

stage.addEventListener("mouseup", (event) => {
  out.textContent =
    "released at " + event.clientX + ", " + event.clientY;
});
Try It Yourself

How It Works

The listener runs when you release—press alone does not fire mouseup.

Example 2 — onmouseup Property

Same idea using the handler property form.

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

stage.onmouseup = (event) => {
  out.textContent = "onmouseup button=" + event.button;
};
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Buttons, pointerup & Drag End

Identify which button, compare with pointerup, and end a drag on release.

Example 3 — Which Button Was Released?

Map event.button to a friendly label.

JavaScript
const stage = document.getElementById("stage");
const out = document.getElementById("out");
const names = { 0: "primary", 1: "middle", 2: "secondary" };

stage.addEventListener("mouseup", (event) => {
  event.preventDefault(); // keep secondary release demos quiet
  out.textContent =
    "button=" + event.button +
    " (" + (names[event.button] || "other") + ")" +
    " buttons=" + event.buttons;
});
Try It Yourself

How It Works

button is the button that changed; buttons is what remains held after the release.

Example 4 — mouseup vs pointerup Counts

Hold two buttons, then release them one at a time and compare fire counts.

JavaScript
const stage = document.getElementById("stage");
const out = document.getElementById("out");
let mouseCount = 0;
let pointerCount = 0;

stage.addEventListener("mouseup", () => {
  mouseCount++;
  render();
});

stage.addEventListener("pointerup", () => {
  pointerCount++;
  render();
});

function render() {
  out.textContent =
    "mouseup=" + mouseCount + " pointerup=" + pointerCount;
}
Try It Yourself

How It Works

MDN notes that physical mice fire mouseup on every button release, while pointerup waits for the last button.

Example 5 — End Drag Tracking on Release

Start on mousedown; clear state on window mouseup so release outside still works.

JavaScript
const handle = document.getElementById("handle");
const out = document.getElementById("out");
let dragging = false;

handle.addEventListener("mousedown", (event) => {
  if (event.button !== 0) return;
  dragging = true;
  handle.classList.add("is-dragging");
  out.textContent = "dragging…";
});

window.addEventListener("mouseup", () => {
  if (!dragging) return;
  dragging = false;
  handle.classList.remove("is-dragging");
  out.textContent = "released — idle";
});
Try It Yourself

How It Works

Listening on window catches releases that happen outside the handle. For production drag UX, prefer Pointer Events + setPointerCapture.

🚀 Common Use Cases

  • End a drag or resize session on release.
  • Clear pressed / active visual feedback.
  • Stop press-and-hold timers when the button goes up.
  • Inspect which mouse button was released.
  • Teach event order alongside mousedown and click.

🔧 How It Works

1

Pointer over element

The hit-tested target is ready for mouse buttons.

Target
2

mousedown

Button pressed; interaction may start here.

Press
3

mouseup

Button released; MouseEvent carries button and coordinates.

Release
4

click (if completed)

Full activation when press+release stay related.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Primary UI actions: prefer click so keyboard users share the same path.
  • For unified mouse/touch/pen, consider Pointer Events (pointerup) and capture APIs.
  • Release can happen on a different element than the press—listen on window when ending drags.
  • Related learning: mousedown, click, mouseover, addEventListener(), JavaScript hub.

Browser Support

mouseup is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. MouseEvent button/buttons and coordinates are supported across modern engines.

Baseline · Widely available

Element mouseup

Fires when a pointing-device button is released; pair with mousedown and prefer click for primary actions.

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 (legacy MouseEvent)
Yes
mouseup Baseline

Bottom line: Safe for release / drag-end UX. Keep primary activate actions on click for accessibility.

Conclusion

mouseup is the immediate “button released” signal. Use it to end presses and drags, pair it with mousedown, and keep primary activation on click.

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

💡 Best Practices

✅ Do

  • Use mouseup to end press feedback and drag sessions
  • Check event.button when non-primary releases matter
  • Listen on window when release may happen outside the start target
  • Prefer click for primary activate actions
  • Prefer addEventListener in production code

❌ Don’t

  • Replace click with mouseup for primary buttons/links
  • Assume every press will also produce a click on the same element
  • Assume mouseup equals pointerup for multi-button mice
  • Forget to clear pressed UI if release happens outside the element
  • Overwrite onmouseup if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about mouseup

Button released now—use click for full activation.

5
Core concepts
📄02

MouseEvent

button · coords

API
👆03

vs click

release ≠ activate

Compare
🔄04

mousedown

press pair

Pair
🎯05

Baseline

widely available

Status

❓ Frequently Asked Questions

It fires when a pointing-device button is released while the pointer is inside the element. It is the counterpoint to mousedown.
No. MDN marks Element mouseup 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 button, buttons, clientX, clientY, and modifier keys such as ctrlKey and shiftKey.
mouseup fires when the button goes up. click fires after a completed press-and-release activation (typically after mousedown and mouseup). Prefer click for primary UI actions so keyboard users are included.
With a physical mouse, mouseup fires whenever any button is released. pointerup fires only for the last button release; earlier releases while other buttons remain held do not fire pointerup.
Use it to end a press, finish a drag, clear pressed styles, or react to a specific button release. Keep primary activate-on-click actions on click.
Did you know?

Holding two mouse buttons and releasing them one by one can produce two mouseup events, but only one pointerup (when the last button goes up). That difference is called out on MDN’s mouseup page.

Next: mousewheel

Learn why the obsolete mousewheel event is deprecated—and how to use wheel instead.

mousewheel →

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