Skip to content

How to trigger click event without clicking JavaScript | Example Code

  • by

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:

trigger click event without clicking JavaScript

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

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading