html onclick href code example

Example 1: javascript onclick href location

onclick="location.href='unit_01.htm'"

Example 2: href on a button

<button onclick="window.location.href='/page2'">Continue</button>

Example 3: html button link

<button><a href='https://google.com' alt='Broken Link'>This is a button</a></button>

Example 4: onclick href

onclick="location.href='http://www.hyperlinkcode.com/button-links.php'"

Example 5: add link behind a button in html

<!DOCTYPE html>
<html>
   <head>
      <title>Title of the document</title>
   </head>
   <body>
      <form>
         <input type="button" onclick="window.location.href = 'https://www.w3docs.com';" value="w3docs"/>
      </form>
   </body>
</html>

Example 6: button as href

<button onclick="location.href='http://www.example.com'" type="button">
         www.example.com</button>