docs.rodeo

MDN Web Docs mirror

HTMLElement: click() method

{{ APIRef("HTML DOM") }} 

The HTMLElement.click() method simulates a mouse click on an element. When called on an element, the element’s {{domxref("Element/click_event", "click")}}  event is fired (unless its disabled attribute is set).

Syntax

click()

Parameters

None.

Return value

None ({{jsxref("undefined")}} ).

Examples

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 occurred')" />
</form>

JavaScript

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

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN