👀 Live Preview
Press and release the button — status updates on mouseup:
Status: waiting for mouseup…

The onmouseup attribute is an inline event handler for the mouseup event. It runs when the user releases a mouse button while the pointer is over an element. That makes it useful for ending press effects, finishing drag operations, or detecting release after onmousedown. It is not the same as onclick, which fires only after a complete press-and-release on the same element. Pass event to read event.button and pointer position. For drags, attach mouseup to document so release outside the element still runs your cleanup code.
Inline JS.
Button up.
Wide support.
Press pair.
Preferred way.
Release only.
onmouseup AttributeThe primary purpose of onmouseup is to run code when a mouse button is released. Common uses include clearing a “pressed” visual state, stopping a drag, completing a slider handle move, or logging that the user finished a press gesture.
In the typical sequence on one element: mousedown → (optional mousemove) → mouseup → click. If the pointer leaves the element before release, mouseup may fire on a different element — which is why drag code listens on document.
onmouseup fires on button release. onclick fires only when down and up happen on the same element without canceling. Use onclick for normal button actions.
Set onmouseup on any element that should respond when a mouse button is released:
<button type="button" onmouseup="handleMouseUp(event)">
Release here
</button>
<div
onmousedown="startPress(this)"
onmouseup="endPress(this)">
Press and release
</div>mouseup event fires.button, div, a, etc.event for button, clientX, clientY.mousedown on the same gesture.click when both occur on the same element.type="button" on buttons inside forms to avoid accidental submit.el.addEventListener("mouseup", handler).The onmouseup attribute accepts a string of JavaScript code:
onmouseup="handleMouseUp(event)" — Pass the event object.onmouseup="endPress(this)" — Reset the element that received release.btn.onmouseup = (e) => { … } — property assignment.box.addEventListener("mousedown", () => {
box.classList.add("pressed");
});
box.addEventListener("mouseup", () => {
box.classList.remove("pressed");
});
// Drag: listen on document so release anywhere ends drag
document.addEventListener("mouseup", () => {
dragging = false;
});| Property / event | When it fires | Notes |
|---|---|---|
mousedown | Button pressed down | onmousedown |
mouseup | Button released | onmouseup |
click | After down + up | onclick |
event.button | In handler | 0 left, 1 middle, 2 right |
| Handler attribute | onmouseup | Inline on element |
| Target | Supported? | Notes |
|---|---|---|
<button> | Yes | Prefer onclick for actions |
<div>, <span> | Yes | Drag handles, custom controls |
<a> | Yes | Rare; navigation uses click |
<input> | Yes | Selection may interfere |
document / window | Via JS | End drag globally |
onmouseup vs onmousedown vs onclick| Handler | When it fires | Typical use |
|---|---|---|
onmousedown | Button pressed down | Start press, begin drag |
onmouseup | Button released | End press, stop drag |
onclick | Full click (down + up) | Button actions, toggles |
onmousemove | While moving over | Drag tracking |
Status on release, addEventListener with event.button, and mousedown + mouseup press state.
Press and release the button — status updates on mouseup:
Status: waiting for mouseup…
Show feedback when the mouse button is released:
<button type="button" onmouseup="handleMouseUp()">
Release me
</button>
<p id="status"></p>
<script>
function handleMouseUp() {
document.getElementById("status").textContent =
"mouseup: Mouse button released!";
}
</script>mouseup fires the instant the button goes up. The handler runs at that moment.
Attach with addEventListener:
<button type="button" id="dynamicButton">
Release mouse here
</button>
<script>
document.getElementById("dynamicButton").addEventListener("mouseup", function (event) {
document.getElementById("log").textContent =
"Released button " + event.button;
});
</script>Register once in script. The handler receives the event with button and coordinates.
Clear pressed styling when the button is released:
box.addEventListener("mousedown", () => {
box.classList.add("pressed");
box.textContent = "Pressed…";
});
box.addEventListener("mouseup", () => {
box.classList.remove("pressed");
box.textContent = "Press and release me";
});mouseup ends the pressed state. For drags, also listen on document for mouseup outside the box.
onclick for actions — Keyboard users activate with Enter/Space; mouseup alone does not cover keyboard.<button> — Not a bare div unless you add keyboard support.After mousedown.
Button goes up.
onmouseup runs.
End drag, unpress.
The mouseup event and onmouseup handler are supported in all browsers, including legacy Internet Explorer.
onmouseup supportEvery major browser fires mouseup when a mouse button is released over elements.
Bottom line: Safe to use for release detection and drag cleanup in any browser.
onmousedown for press-and-release UXdocument.addEventListener("mouseup", …) to end dragsonclick for standard button actionsevent to read button and coordinatesaddEventListener("mouseup", …) in productionalert() for release feedbackThe onmouseup attribute runs JavaScript when a mouse button is released over an element — ideal for ending press states, stopping drags, and completing pointer gestures.
Pair it with onmousedown, use onclick for normal actions, and listen on document when release may happen outside the target.
onmouseupBookmark these before handling pointer release.
On release.
EventSame gesture.
OrderCleanup.
UXIf same el.
SequenceFor actions.
A11ymouseup event fires — when the user releases a mouse button while the pointer is over the element.mouseup is release only. click requires mousedown and mouseup on the same element without cancellation.addEventListener("mouseup", handler) is preferred for production code.Practice the onmouseup attribute with release feedback examples in the Try It editor.
5 people found this page helpful