Skip to content

HTML onclick href | Uses example code

  • by

You can Execute a JavaScript code or function inside the onclick attribute when a button is clicked.

 <element onclick="myScript"> 

Or load page/ website


html onclick href Example

HTML Example code:

Anchore <a> Tag

<a href="javascript:alert('Hello');"></a>


	<a href="Javascript: doStuff();">link</a>

		function doStuff() {
			alert("Do Stuff")



HTML onclick href

HTML Button

	<button onclick="location.href=''"></button>

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

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 *