Skip to content

Execute JavaScript on link click | Example code

  • by

There are many ways to Execute a JavaScript function in an HTML document. Using the onclick event attribute simple way to Execute JavaScript on link click.

HTML example code: use the onclick event, something like this:



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

		function add(a,b){



Execute JavaScript on link click

Another way using the href

<a href="#" onclick="Hello(); return false;">LINK</a>

	function Hello(){
		console.log("Hello function")

Do comment if you have any doubts and suggestions on this JS link 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

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