javascript onclick href code example

Example 1: javascript onclick href location

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

Example 2: onclick href

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

Example 3: onclick a tag

<a href='http://www.google.com' onclick='return check()'>check</a>

<script type='text/javascript'>
function check() {
    return false;
}
</script>

Example 4: on click in a tag

<a onclick='newwin()'>Anchor</a>

Example 5: javascript onclick button

var button = document.querySelector('button');
button.onclick = function() {
  //do stuff
}

Tags:

Html Example