Favorites

DOM Element: click event

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Element: click event
DOM Element EventThis event is supported by all modern browsers.
Updated 28th November 2026

The click event fires when an element is activated by a mouse click, a tap, or the Enter or Space key on buttons and links.

Description

The click event fires when a pointing device button is pressed and released on the same element, when it is tapped on a touch screen, and when a <button>, link or form control is activated with the keyboard. That last point is why using real buttons and links makes clickable things accessible for free.

The listener receives a PointerEvent (a kind of MouseEvent) with the position and button. Because click bubbles, you can handle clicks on many elements with one listener on a parent. Call preventDefault() to stop a link from navigating or a submit button from sending its form.

The detail property counts rapid clicks, so it's 2 for the second click of a double-click, and the separate dblclick event fires after two clicks. event.button tells you which mouse button was used, but click only fires for the main button; listen for auxclick or contextmenu for the others.

Syntax

element.addEventListener('click', handler)
element.onclick = handler

Example

<button id="btn" type="button">Click me</button>
const btn = document.getElementById('btn');
let clicks = 0;
btn.addEventListener('click', e => {
  clicks++;
  console.log('click', clicks, 'detail:', e.detail);
});
console.log('Click the button, or Tab to it and press Enter');

Browser Support

The following information will show you the current browser support for the Element: click event event. Hover over a browser icon to see the version that first introduced support for this event.

This event is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee