DOM Element: click event
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 = handlerExample
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.
Desktop





Tablets & Mobile





