JavaScript Element mousedown Event

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

What You’ll Learn

The mousedown event fires when a pointing-device button is pressed inside an element. Learn addEventListener vs onmousedown, button / buttons, how it differs from click and pointerdown, press-and-hold patterns, and five try-it labs.

01

Kind

Instance event

02

Type

MouseEvent

03

When

Button pressed

04

Handler

onmousedown

05

Pair

mouseup

06

Status

Baseline widely available

Introduction

mousedown answers: “Did the user just press a pointing-device button while the pointer was over this element?” It fires the moment the button goes down—not after release.

That is different from click, which waits for a full press and release inside the same element. Use mousedown for drag start, press feedback, or press-and-hold. Prefer click for primary UI actions so keyboard users are included.

💡
Beginner tip

With a physical mouse, mousedown fires for every button press. pointerdown fires only for the first button; later buttons held at the same time do not fire more pointerdown events.

Understanding mousedown

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

  • Fires when a button is pressed while the pointer is inside the element.
  • MouseEventbutton, buttons, coordinates, modifiers.
  • Handleronmousedown or addEventListener("mousedown", ...).
  • Order — usually before mouseup and (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("mousedown", (event) => { });

onmousedown = (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 currently held down
clientX / clientYPointer position in the viewport
ctrlKey / shiftKey / altKey / metaKeyModifier keys at press time

⚡ When mousedown Fires

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

A typical completed left-click sequence is: mousedownmouseupclick.

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("mousedown", fn)
Handler propertyel.onmousedown = fn
Which buttonevent.button (0 / 1 / 2)
Positionevent.clientX, event.clientY
Primary actionsPrefer click for accessibility
MDN statusBaseline Widely available

🔍 At a Glance

Four facts to remember about mousedown.

Event type
MouseEvent

UIEvent + Event

Means
button down

Press, not release

Key field
button

0 · 1 · 2

Baseline
yes

Widely available

Examples Gallery

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

📚 Getting Started

Listener patterns and the onmousedown property.

Example 1 — Log Press Position

Show viewport coordinates when the button goes down.

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

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

How It Works

The listener runs as soon as you press—no need to release the button.

Example 2 — onmousedown Property

Same idea using the handler property form.

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

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

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Buttons, Order & Drag Start

Identify which button, compare event order, and start a drag session on press.

Example 3 — Which Button Was Pressed?

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("mousedown", (event) => {
  event.preventDefault(); // keep secondary press from opening the menu in demos
  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 the set currently held.

Example 4 — mousedown → mouseup → click

Log the classic mouse activation sequence.

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

["mousedown", "mouseup", "click"].forEach((type) => {
  stage.addEventListener(type, () => {
    log.push(type);
    out.textContent = log.join(" → ");
  });
});
Try It Yourself

How It Works

If you press and drag out before release, you may still get mousedown / mouseup without a click on that element.

Example 5 — Start Drag Tracking on Press

Enter a dragging state on mousedown; clear it on mouseup.

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 = "idle";
});
Try It Yourself

How It Works

For robust drag UX, consider Pointer Events + setPointerCapture so moves keep targeting your handle outside its bounds.

🚀 Common Use Cases

  • Start a drag or resize session on press.
  • Show immediate pressed / active visual feedback.
  • Press-and-hold timers (open menus, continuous scrub).
  • Inspect which mouse button started an interaction.
  • Teach event order alongside mouseup and click.

🔧 How It Works

1

Pointer over element

The hit-tested target is ready for mouse buttons.

Target
2

mousedown

Button pressed; MouseEvent carries button and coordinates.

Press
3

mouseup

Button released (possibly on a different element).

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 ( pointerdown ) and capture APIs.
  • Right-click may open a context menu; call preventDefault() only when your demo/app needs it.
  • Related learning: mouseup, click, lostpointercapture, auxclick, addEventListener(), JavaScript hub.

Browser Support

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

Fires when a pointing-device button is pressed; pair with mouseup 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
mousedown Baseline

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

Conclusion

mousedown is the immediate “button pressed” signal. Use it for press feedback and drag start, pair it with mouseup, and keep primary activation on click.

Continue with mouseenter, click, lostpointercapture, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use mousedown for press feedback and drag start
  • Check event.button when non-primary presses matter
  • Clear press state on mouseup / blur / pointercancel
  • Prefer click for primary activate actions
  • Prefer addEventListener in production code

❌ Don’t

  • Replace click with mousedown for primary buttons/links
  • Assume every press will also produce a click on the same element
  • Ignore middle/right presses if your UI treats them specially
  • Forget that pointerdown behaves differently for multi-button mice
  • Overwrite onmousedown if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about mousedown

Button pressed now—use click for full activation.

5
Core concepts
📄02

MouseEvent

button · coords

API
👆03

vs click

press ≠ activate

Compare
🔄04

mouseup

release pair

Pair
🎯05

Baseline

widely available

Status

❓ Frequently Asked Questions

It fires when a pointing-device button is pressed while the pointer is inside the element. Unlike click, it fires at the moment of press — before release.
No. MDN marks Element mousedown 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.
mousedown fires when the button goes down. click fires after a full press-and-release inside the same element (after mousedown and mouseup). Prefer click for primary UI actions so keyboard users are included.
With a physical mouse, mousedown fires for every button press. pointerdown fires only for the first button press; extra buttons held at the same time do not fire more pointerdown events.
Use it for press feedback, drag start, press-and-hold, or when you need the button identity immediately. Keep primary activate-on-click actions on click.
Did you know?

Holding two mouse buttons can produce multiple mousedown events, but pointerdown typically fires only for the first button. That is one reason MDN highlights the difference between mouse and pointer models.

Next: mouseenter

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

mouseenter →

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