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
element.click()
Example
Simulate a mouse-click when moving the mouse pointer over a checkbox:
HTML
<form> <input type="checkbox" id="myCheck" onmouseover="myFunction()" onclick="alert('click event occured')"> </form>
JavaScript
// On mouse-over, execute myFunction function myFunction() { document.getElementById("myCheck").click(); }
Specification
Specification | Status | Comment |
---|---|---|
HTML Living Standard | Living Standard | |
Document Object Model (DOM) Level 2 HTML Specification | Obsolete | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
click() | Chrome
Full support
9
| Edge Full support 12 | Firefox
Full support
3
| IE Full support 8 | Opera Full support 10.5 | Safari Full support 6 | WebView Android
Full support
≤37
| Chrome Android
Full support
18
| Firefox Android Full support 5 | Opera Android Full support 11 | Safari iOS Full support 6 | Samsung Internet Android
Full support
1.0
|
Legend
- Full support
- Full support
- See implementation notes.
- See implementation notes.
See also
- Related event handlers