HTML a href call JavaScript function | Example code

  • by

You can use href or on click method to call a JavaScript function from HTML elements.

A href call function : href

<a href="javascript:yourFunction();">

HTML a href call JavaScript function example

Simple addition function will call on clicking the link, where function will call from href attribute.

In the example we are doing call JavaScript function from href with parameters, you can do it without parameter also.



	<a href="javascript:add(1,2)" id="fo">JS Add Numbers</a>

		function add(a,b){



HTML a href call JavaScript function

Do comment if you have any doubts and suggestions on this HTML topic.

Note: The All HTML Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.