W3cubDocs

/Web APIs

HTMLElement: click() method

The HTMLElement.click() method simulates a mouse click on an element.

When click() is used with supported elements (such as an <input>), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.

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"
    onmouseover="myFunction()"
    onclick="alert('click event occurred')" />
</form>

JavaScript

js

// On mouse-over, execute myFunction
function myFunction() {
  document.getElementById("myCheck").click();
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
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."]
5.5 10.5 6
4.4Before Android WebView 4.4, click() is only defined on buttons and inputs.
18Before Chrome 19, 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.

See also

© 2005–2023 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