JavaScript Element dblclick Event

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

What You’ll Learn

The dblclick event fires when a pointing device double-clicks an element. Learn addEventListener vs ondblclick, order vs click, MouseEvent coordinates, UX tips, and five try-it labs.

01

Kind

Instance event

02

Type

MouseEvent

03

After

Two click events

04

Handler

ondblclick

05

Useful fields

clientX / clientY

06

Status

Baseline widely available

Introduction

A double-click is two rapid primary-button clicks on the same element. Desktop apps often use it for shortcuts: rename a file, zoom a map, expand a card, or open an item.

In the DOM, dblclick arrives after two click events have already fired. That means a double-click also runs any click listeners twice unless you design carefully.

💡
Beginner tip

Keep primary actions on click. Use dblclick for optional power features, and offer a visible button or menu item for the same result.

Understanding dblclick

An instance event that answers: “Was this element double-clicked with a pointing device?”

  • Fires on a rapid double primary-button click.
  • Order — after two click events (each after mousedown + mouseup).
  • MouseEvent — coordinates, button, modifier keys.
  • Handlerondblclick or addEventListener("dblclick", ...).
  • Baseline Widely available on MDN (since July 2015).

📝 Syntax

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

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

ondblclick = (event) => { };

Event type

A MouseEvent (inherits from UIEvent and Event).

Handy properties

PropertyMeaning
clientX / clientYPointer position in the viewport
buttonWhich mouse button was used (primary is usually 0)
ctrlKey / shiftKey / altKey / metaKeyModifier keys held during the event

🔁 Event Order

  1. mousedownmouseupclick (first click)
  2. mousedownmouseupclick (second click)
  3. dblclick

If both click and dblclick handlers change the same UI, the first click may run before your double-click intent is clear. Prefer separate targets or delayed single-click logic only when you truly need it.

⚖️ dblclick vs click

Topicclickdblclick
TriggerSingle activationTwo rapid activations
Best forPrimary actionsOptional shortcuts
Keyboard / touchOften supportedLess reliable on touch
Event type (modern)Often PointerEventMouseEvent on MDN

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("dblclick", fn)
Handler propertyel.ondblclick = fn
Toggle UIel.classList.toggle("large")
Pointer positionevent.clientX, event.clientY
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts to remember about dblclick.

Event type
MouseEvent

UIEvent + Event

Means
double-click

Two rapid clicks

After
click × 2

Then dblclick

Baseline
yes

Widely available

Examples Gallery

Examples follow MDN Element: dblclick event. Double-click the demo targets with a mouse (or trackpad).

📚 Getting Started

MDN-style card resize and the handler property.

Example 1 — Toggle size on dblclick (MDN)

Double-click a card to toggle a large class.

JavaScript
const card = document.querySelector("aside");

card.addEventListener("dblclick", (e) => {
  card.classList.toggle("large");
});
Try It Yourself

How It Works

CSS transitions make the size change smooth. user-select: none reduces accidental text selection while double-clicking.

Example 2 — ondblclick Property

Same idea using the handler property.

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

box.ondblclick = () => {
  box.textContent = "Double-clicked!";
};
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Coords, Count & Order

Log where the double-click happened, count them, and see click order.

Example 3 — Log clientX / clientY

Useful before placing a menu or marker at the pointer.

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

area.addEventListener("dblclick", (event) => {
  out.textContent = "x=" + event.clientX + ", y=" + event.clientY;
});
Try It Yourself

How It Works

Coordinates are viewport-relative. Convert if you need page or element-local positions.

Example 4 — Count Double-Clicks

Simple counter for demos and debugging.

JavaScript
const target = document.getElementById("target");
const out = document.getElementById("out");
let n = 0;

target.addEventListener("dblclick", () => {
  n += 1;
  out.textContent = "dblclick count: " + n;
});
Try It Yourself

How It Works

Each successful double-click increments once—not once per individual click.

Example 5 — See click Then dblclick

Log both events so the order is obvious.

JavaScript
const el = document.getElementById("el");
const log = document.getElementById("log");

function add(msg) {
  log.textContent += msg + "\n";
}

el.addEventListener("click", () => add("click"));
el.addEventListener("dblclick", () => add("dblclick"));
Try It Yourself

How It Works

That log is why mixing heavy logic in both handlers can feel “jumpy.” Keep roles separate.

🚀 Common Use Cases

  • Expanding or resizing a card (MDN’s classic demo).
  • Starting inline rename on a file or list item.
  • Zooming a map or image preview.
  • Opening a detail view as a power-user shortcut.
  • Selecting a word / paragraph in custom editors (browser default often does this too).

🔧 How It Works

1

First click completes

mousedown, mouseup, then click.

Click 1
2

Second click completes quickly

Another mousedown / mouseup / click pair.

Click 2
3

dblclick fires

Your double-click handler runs on the target element.

Event
4

Shortcut action runs

Resize, rename, zoom, or whatever you wired up.

📝 Notes

  • MDN: Baseline Widely available (since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Two click events fire before dblclick.
  • Touch double-tap support is inconsistent—provide another control.
  • Related learning: click, cut, DOMActivate, addEventListener(), JavaScript hub.

Universal Browser Support

dblclick is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. Double-tap timing on touch devices still varies.

Baseline · Widely available

Element dblclick

Works across modern desktop browsers for mouse double-clicks; offer alternatives on touch.

100% Widely available
Google Chrome Supported · Desktop & Android
Full support
Mozilla Firefox Supported · Desktop & Android
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Opera Supported · Modern versions
Full support
Internet Explorer Supported (legacy)
Supported
dblclick Baseline

Bottom line: Use dblclick for optional desktop shortcuts after two clicks; keep primary actions on click.

Conclusion

dblclick is the “user double-clicked” signal. It arrives after two click events—great for optional shortcuts, not as the only way to do a critical action.

Continue with DOMActivate, click, addEventListener(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer addEventListener("dblclick", ...)
  • Use dblclick for optional power-user shortcuts
  • Provide a button / menu fallback for the same action
  • Consider user-select: none when double-click selects unwanted text
  • Test that single click handlers still feel right

❌ Don’t

  • Hide primary actions behind double-click only
  • Ignore that two click events fire first
  • Assume touch double-tap equals mouse dblclick everywhere
  • Forget accessibility alternatives
  • Overwrite ondblclick if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about dblclick

Two rapid clicks—after click×2; use for shortcuts, not sole primary actions.

5
Core concepts
📄 02

MouseEvent

coords + keys

API
🔁 03

After click×2

then dblclick

Order
04

Shortcut UX

not only path

Pattern
🎯 05

Baseline

widely available

Compat

❓ Frequently Asked Questions

It fires when a pointing-device primary button is double-clicked on an element — two rapid clicks within a short time span.
No. MDN marks Element dblclick 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 clientX, clientY, button, and modifier keys.
dblclick fires after two click events (and therefore after two pairs of mousedown and mouseup).
Usually no. Prefer click for main actions so touch and keyboard users are included. Use dblclick for optional shortcuts such as rename, zoom, or expand.
Double-tap behavior varies by device and browser. Always provide a single-tap or button alternative for the same action.
Did you know?

MDN’s card demo toggles a large CSS class on double-click and uses user-select: none so the browser does not highlight the card text while you practice double-clicking.

Next: DOMActivate

See the deprecated activation event—and why click replaced it.

DOMActivate →

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