How to call javascript function from html ?

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

In jsFile1.js

	function chkFunc(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