The click()
method simulates a mouse-click on an element.
click |
Yes | Yes | Yes | Yes | Yes |
HTMLElementObject.click()
None
No return value
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: