If you want native JS to trigger click event without clicking then use the element id and click() method of JavaScript.
Syntax: JavaScript trigger click on the element
document.getElementById('myElementID').click();
Trigger click event without clicking in JavaScript Example
Complete HTML example code:
Create one button with “trigger” id and assign msg() function to the onClick attribute. If the button clicks then msg() function triggers a popup alert.
<html>
<body>
<button id="trigger" onclick="msg()">Auto Click</button>
<script>
document.getElementById("trigger").click();
function msg(){
alert("Auto click");
}
</script>
</body>
</html>
Output:
Do comment if you have any doubts or suggestions on this JS event topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version