MDN Web Docs

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

See also

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗