JavaScript Element auxclick Event

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

What You’ll Learn

The auxclick event fires when a non-primary pointer button (middle, right, or other) is pressed and released on the same element. Learn addEventListener vs onauxclick, event.button, how to cancel browser defaults, and how it differs from click—with five examples and try-it labs.

01

Kind

Instance event

02

Type

PointerEvent

03

When

Non-primary click

04

Handler

onauxclick

05

Order

After mouseup

06

Status

Baseline 2024

Introduction

The familiar click event covers the primary button (usually left). For every other button—middle-click, right-click, and extra mouse buttons— browsers fire auxclick instead when press and release both happen on the same element.

MDN: auxclick fires after mousedown and mouseup, in that order. That makes it the “click completed” signal for non-primary buttons.

💡
Beginner tip

You need a multi-button mouse (or equivalent) to try most demos. Touchscreens and trackpads may not produce a true middle-click. Prefer addEventListener("auxclick", ...) for production code.

Understanding auxclick

An instance event for non-primary pointer button clicks. It answers: “Did the user click this element with a button other than the primary one?”

  • Fires on non-primary button press + release on the same element.
  • After mousedown then mouseup.
  • PointerEvent today (inherits MouseEvent fields like button).
  • Baseline 2024 — newly available across latest browsers since Dec 2024.

📝 Syntax

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

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

onauxclick = (event) => { };

Event type

A PointerEvent (inherits from MouseEvent). Earlier specs used MouseEvent; check compatibility if you rely on Pointer-only fields.

Useful inherited properties

PropertyMeaning
buttonWhich button changed: 1 middle, 2 right (typical)
buttonsBitmask of buttons currently held
clientX / clientYPointer position in the viewport
pointerTypeDevice type when exposed as PointerEvent (mouse, etc.)

⚠️ Preventing Default Actions

MDN highlights a few browser defaults that pair with non-primary clicks:

  • Middle-click open in new tab — usually cancelable with preventDefault() on auxclick.
  • Right-click context menu — prevent on contextmenu, not only on auxclick (OS timing differs).
  • Middle-button down actions (autoscroll on Windows, paste on some macOS/Linux setups) — prevent on mousedown / pointerdown.

⚖️ auxclick vs click vs contextmenu

EventTypical triggerUse for
clickPrimary (left) buttonMain UI actions
auxclickNon-primary buttonsMiddle/right/extra button actions
contextmenuRight-click / keyboard menu keyCustom menus; cancel system menu

🌐 Baseline 2024 (Newly Available)

MDN marks auxclick as Baseline 2024: newly available across the latest devices and browser versions since December 2024. It is not Deprecated, Experimental, or Non-standard—but older browsers may lack support, so feature-detect or provide a fallback if you support legacy clients.

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("auxclick", fn)
Handler propertyel.onauxclick = fn
Which button?event.button (1 middle, 2 right)
Block new tabevent.preventDefault() in auxclick
Block context menupreventDefault() on contextmenu
Event ordermousedownmouseupauxclick
MDN statusBaseline 2024 (newly available)

🔍 At a Glance

Four facts to remember about auxclick.

Event type
PointerEvent

via MouseEvent

Means
non-primary

Not left-click

After
mouseup

Then auxclick

Baseline
2024

Newly available

Examples Gallery

Examples follow MDN Element: auxclick event. Try It Yourself labs work best with a multi-button mouse—middle-click or right-click the targets.

📚 Getting Started

Register handlers the MDN ways.

Example 1 — addEventListener("auxclick")

Listen for any non-primary button click on an element.

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

box.addEventListener("auxclick", () => {
  console.log("auxclick fired");
});

// Middle-click or right-click the box (not left-click).
Try It Yourself

How It Works

Left-click uses click. Middle/right (and other non-primary) buttons use auxclick when press and release stay on the same target.

Example 2 — onauxclick Property

MDN-style handler property (inspired by the color-button demo).

JavaScript
const button = document.querySelector("button");

button.onclick = () => {
  console.log("Primary click (left)");
};

button.onauxclick = () => {
  console.log("Auxiliary click (non-primary)");
};

// Assigning again replaces the previous onauxclick handler.
Try It Yourself

How It Works

Split primary and auxiliary actions cleanly: onclick for left, onauxclick for everything else.

📈 Button, Defaults & Order

Inspect button, cancel defaults, and log the event sequence.

Example 3 — Read event.button

Tell middle-click from right-click (and other buttons).

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

box.addEventListener("auxclick", (event) => {
  const names = { 1: "middle", 2: "right", 3: "back", 4: "forward" };
  console.log("button:", event.button, names[event.button] || "other");
});
Try It Yourself

How It Works

button identifies which non-primary button completed the click. Gaming mice may report additional button numbers.

Example 4 — preventDefault + contextmenu

MDN pattern: change UI on auxclick and block the system context menu.

JavaScript
const button = document.querySelector("button");

function random(number) {
  return Math.floor(Math.random() * number);
}

function randomColor() {
  return `rgb(${random(255)} ${random(255)} ${random(255)})`;
}

button.onclick = () => {
  button.style.backgroundColor = randomColor();
};

button.onauxclick = (e) => {
  e.preventDefault(); // e.g. block middle-click open-in-new-tab when relevant
  button.style.color = randomColor();
};

button.oncontextmenu = (e) => {
  e.preventDefault(); // stop the system right-click menu
};
Try It Yourself

How It Works

auxclick alone cannot reliably cancel every OS menu. Pair it with contextmenu when you need a custom right-click experience.

Example 5 — Event Order

Confirm MDN’s order: mousedownmouseupauxclick.

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

["mousedown", "mouseup", "auxclick", "click"].forEach((type) => {
  box.addEventListener(type, (event) => {
    log.push(type + " (button " + event.button + ")");
    console.log(log.join(" → "));
  });
});

// Middle-click the box and watch the sequence.
Try It Yourself

How It Works

Left-click produces click instead of auxclick. Non-primary buttons produce auxclick after the down/up pair.

🚀 Common Use Cases

  • Custom middle-click actions on cards or list items.
  • Right-click shortcuts that also cancel the system menu.
  • Teaching pointer button differences next to click.
  • Blocking open-in-new-tab when middle-click should mean something else.
  • Handling extra mouse buttons on power-user UIs.

🔧 How It Works

1

Non-primary button down

mousedown / pointerdown fire first.

Down
2

Same button up on same element

mouseup fires on the target.

Up
3

Browser fires auxclick

A PointerEvent / MouseEvent is dispatched.

Event
4

Your handler runs

Inspect button, update UI, or call preventDefault().

📝 Notes

  • MDN: Baseline 2024 (newly available since December 2024).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Primary-button clicks use click, not auxclick.
  • Cancel context menus with contextmenu; cancel middle-click navigation with auxclick.
  • Related learning: animationstart, addEventListener(), MouseEvent, JavaScript hub.

Modern Browser Support

auxclick is marked Baseline 2024 on MDN (newly available since December 2024). Logos use the shared browser-image-sprite.png sprite from this project. Older browsers may lack it—test if you support legacy clients.

Baseline 2024 · Newly available

Element auxclick

Works across the latest major browsers for non-primary pointer button clicks.

2024 Baseline year
Google Chrome Supported · Modern versions
Full support
Mozilla Firefox Supported · Modern versions
Full support
Apple Safari Supported in Baseline 2024 set
Full support
Microsoft Edge Supported · Chromium
Full support
Opera Supported · Modern versions
Full support
Internet Explorer No auxclick support
Unavailable
auxclick Baseline 2024

Bottom line: Use for middle/right/extra button clicks. Pair with contextmenu and mousedown preventDefault when canceling browser defaults.

Conclusion

auxclick is the non-primary-button counterpart to click. Listen with addEventListener, inspect event.button, and use the right companion events (contextmenu, mousedown) when you need to cancel browser defaults.

Continue with beforeinput, addEventListener(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer addEventListener("auxclick", ...)
  • Check event.button when middle vs right matters
  • Prevent contextmenu when building custom right-click UI
  • Test with a real multi-button mouse
  • Keep primary actions on click for accessibility

❌ Don’t

  • Expect auxclick from left-click
  • Assume every device has a middle button
  • Rely only on auxclick to hide the context menu
  • Ignore Baseline 2024 if you still support very old browsers
  • Overwrite onauxclick if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about auxclick

Non-primary button click completed—handle middle, right, and extras.

5
Core concepts
📍 02

PointerEvent

+ MouseEvent

API
🔢 03

event.button

1 / 2 / …

Detail
🚫 04

Defaults

aux + contextmenu

Cancel
🎯 05

Baseline 2024

newly available

Compat

❓ Frequently Asked Questions

It fires when a non-primary pointing device button (any mouse button other than the primary/left button) is pressed and released on the same element. Typical cases are middle-click and right-click.
No. MDN marks Element auxclick as Baseline 2024 (Newly available since December 2024). It is not Deprecated, Experimental, or Non-standard.
A PointerEvent (inherits from MouseEvent). Older browsers may expose it as a MouseEvent. Useful inherited fields include button, buttons, clientX/clientY, and modifier keys.
After both mousedown and mouseup have fired, in that order, for the non-primary button press/release on the same element.
Yes in most browsers that map middle-click to open-in-new-tab: call event.preventDefault() inside the auxclick handler. To block the right-click context menu, preventDefault on the contextmenu event instead.
click is for the primary button. auxclick is for non-primary buttons. Use click for left-click UI and auxclick for middle/right (and other) buttons.
Did you know?

On many gaming mice, “special” side buttons also count as non-primary and can fire auxclick. Always inspect event.button instead of assuming only middle and right exist.

Next: beforeinput

Learn the event that fires before input and textarea values change.

beforeinput →

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