Count button clicked times - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Count button clicked times

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Space Clicker</title> 
   </head> 
   <body> 
      <script type="text/javascript">
    var clicks = 0;/*w w  w .  j  av a2  s  .c o  m*/
    function incrementClick() {
        clicks += 1;
        document.getElementById("clicks").innerHTML = clicks;
    };
    
      </script> 
      <button type="button" onclick="incrementClick()">Click me</button> 
      <p>
         Clicks: 
         <a id="clicks">0</a>
      </p> 
   </body>
</html>

Related Tutorials