Method 1: Using Script Tag
Method 2: Using HTML event attributes like onClick(), onBlur(), onSubmit():
The clickEvent() function lets them execute the alert() when the button gets clicked by using the onclick() method.
Some on usefull Event Attributes
for a complete list of HTML Event Attributes click here
In the program mentioned above, we have built a simple HTML document. Within the head section of the HTML document, inside the script tags "<script>...</script>" we have used a user-defined function called the func(). We can build a link or a button and use an onclick() event associated with them to call the "func" function.
We have used the onclick attribute and displayed a button for calling the function. When a user clicks on the given button, the browser executes the function and displays the alert message, as displayed in the output console.
Method 3: Using href attribut of anchor tag
Method 4: Using external files to call a function in HTML: