Use <a> element onclick function to add 5 to variable - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

Use <a> element onclick function to add 5 to variable

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from w w w  .j a va2s.  c  o  m
var strt = 0;
var num = 0;
increment = function(event) {
    event.preventDefault(); //Prevent Default a link behavior.
    strt = strt + 5;
    num = num + 5;
    console.log(strt + " -- " + num);
}
    }

      </script> 
   </head> 
   <body> 
      <a href="#" onclick="increment(event)">Some Link</a>  
   </body>
</html>

Related Tutorials