HTMLElement: click() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The HTMLElement.click() method simulates a mouse click on an element. When called on an element, the element's click event is fired (unless its disabled attribute is set).

Syntax

js
click()

Parameters

None.

Return value

None (undefined).

Examples

Simulate a mouse-click when moving the mouse pointer over a checkbox:

HTML

html
<form>
  <input type="checkbox" id="myCheck" />
</form>

JavaScript

js
const checkbox = document.getElementById("myCheck");

// On mouse-over, execute myFunction
checkbox.addEventListener("mouseover", () => {
  // Simulate a mouse click
  checkbox.click();
});

checkbox.addEventListener("click", () => {
  console.log("click event occurred");
});

Specifications

Specification
HTML
# dom-click-dev

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
click
Chrome – Full support
Chrome 9 (Release date: 2011-02-03)
footnote
footnote Before Chrome 19, click() is only defined on buttons and inputs.
Edge – Full support
Edge 12 (Release date: 2015-07-29)
footnote Full support
Firefox – Full support
Firefox 3 (Release date: 2008-06-17)
footnote
footnote Before Firefox 5, click() is only defined on buttons and inputs, and has no effect on text and file inputs.
footnote Starting in Firefox 75, the click() function works even when the element is not attached to a DOM tree.
Opera – Full support
Opera 10.5 (Release date: 2010-03-02)
footnote Full support
Safari – Full support
Safari 6 (Release date: 2012-07-25)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote
footnote Before Chrome Android 25, click() is only defined on buttons and inputs.
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote
footnote Before Firefox 5, click() is only defined on buttons and inputs, and has no effect on text and file inputs.
footnote Starting in Firefox for Android 79, the click() function works even when the element is not attached to a DOM tree.
Opera Android – Full support
Opera Android 11 (Release date: 2011-03-22)
footnote Full support
Safari on iOS – Full support
Safari on iOS 6 (Release date: 2012-09-10)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote
footnote Before Samsung Internet 1.5, click() is only defined on buttons and inputs.
WebView Android – Full support
WebView Android 4.4 (Release date: 2013-12-09)
footnote
footnote Before WebView Android 4.4, click() is only defined on buttons and inputs.
WebView on iOS – Full support
WebView on iOS 6 (Release date: 2012-09-10)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

See also