onclick a tag javascript code example

Example 1: onclick a tag

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

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

Example 2: onclick on anchor tag

<a href='more.php' onclick='show_more_menu()'>More >>></a>

Example 3: a tag onclick

<a href="javascript:show_more_menu();">More >>></a>

Example 4: onclick in js

<input type="text" name="text" id="test" onmouseover="skriv('klick')">
    <input type="button" name="send" value="Skicka" id="klick" onclick="skriv('test')">
    
    
    <script src="lib/script.js"></script>


// in lib/script.js

  function skriv(name) {
    document.getElementById(name).style.backgroundColor='red';
  }

Tags:

Misc Example