W3cubDocs

/Web APIs

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

click()

Parameters

None.

Return value

None (undefined).

Examples

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

HTML

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

JavaScript

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
9Before Chrome 19, click() is only defined on buttons and inputs.
12
3["Before Firefox 5, click() is only defined on buttons and inputs, and has no effect on text and file inputs.", "Starting in Firefox 75, the click() function works even when the element is not attached to a DOM tree."]
10.5 6
18Before Chrome Android 25, click() is only defined on buttons and inputs.
4["Before Firefox 5, click() is only defined on buttons and inputs, and has no effect on text and file inputs.", "Starting in Firefox for Android 79, the click() function works even when the element is not attached to a DOM tree."]
11 6
1.0Before Samsung Internet 1.5, click() is only defined on buttons and inputs.
4.4Before WebView Android 4.4, click() is only defined on buttons and inputs.
6

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click