Ads by ProfitSence
Close

How to call javascript function from html ?

Last Updated on Wednesday 5th Oct 2022
  • There are many ways to call a javascript function in HTML.
			
					<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <script src="./jsFile1.js"></script>
    </head>
    <body >        
        <button onclick="chkFunc(1)">Button 1</button>
        <button id="btn2">Button 1</button>
    </body>
</html>

			
	

In jsFile1.js

			
					function chkFunc(val1) {
    console.log(val1);
}

			
	
  • Call JavaScript Function on HTML Button OnClick.
  • When the Second button is clicked, the JavaScript function is invoked.
			
					document.getElementById("btn2").onclick = clickEvent;

			
	
  • That's what we can call javascript function on HTML button On Clink