Javascript Reference - HTML DOM click() Method








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

Browser Support

click Yes Yes Yes Yes Yes

Syntax

HTMLElementObject.click()

Parameters

None

Return Value

No return value

Example

The following code shows how to simulate a mouse-click when moving the mouse pointer over a checkbox.


<!DOCTYPE html>
<html>
<body>
<form>
  <input type="checkbox" id="myCheck" 
        onmouseover="myFunction()" onclick="console.log('click event occured')">
</form><!--from   ww w .j  a  va 2s  .  c  om-->

<script>
function myFunction() {
    document.getElementById("myCheck").click();
}
</script>


</body>
</html>

The code above is rendered as follows: