The read-only button property is a number for which mouse button was pressed or released to trigger the event (MDN). Do not confuse it with buttons (which buttons are currently held).
Read the notes below before you rely on this property. Prefer feature detection when support is limited.
Syntax
Use event.button. Start with this line.
JavaScript
event.button
Call
What it does
event.button
Primary signature.
Built into the browser. Read event.button on a MouseEvent — no import required.
Library declarations
JavaScript
event.button
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Number 0–4 (common)
JavaScript Examples
Example 1 — mouseup Switch
MDN pattern: map button to a short message.
JavaScript
el.addEventListener("mouseup", (e) => {
switch (e.button) {
case 0: console.log("Left"); break;
case 1: console.log("Middle"); break;
case 2: console.log("Right"); break;
default: console.log("Other", e.button);
}
});
Also set buttons if your handler reads the bitmask.
Compatibility
Browser Support
MouseEvent.button is marked Baseline Widely available on MDN (since July 2015).
✓ Baseline · Widely available
MouseEvent.button
Number for which button was pressed or released. Prefer mousedown/mouseup. Do not confuse with buttons.
100%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
buttonExcellent
Bottom line: Safe everyday API on press/release events. See the MDN button reference.
Frequently Asked Questions
A read-only number that indicates which button was pressed or released to trigger that event. Common values: 0 main/left, 1 auxiliary/middle, 2 secondary/right, 3 back, 4 forward.
No. MDN marks MouseEvent.button as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
button tells which button changed for press/release-related events. buttons is a bit-field of which buttons are currently held and can be used more broadly across mouse event types.
MDN says it only guarantees meaning during events caused by pressing or releasing buttons. It is not reliable for mouseenter, mouseleave, mouseover, mouseout, or mousemove.
Not necessarily. Remapped devices (for example left-handed layouts) may reverse physical buttons. Value 0 means the main button action—usually left in a standard layout.
Pass button in the options to new MouseEvent("mouseup", { button: 2 }). Remember button and buttons use different number systems.