Element click() Method - Javascript DOM

Javascript examples for DOM:Element click

Description

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

Parameters

None

Return Value:

No return value

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Hover over the checkbox to simulate a mouse-click.</p>

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

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


</body>
</html>

Related Tutorials