Incrementing click count in an HTML button - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Incrementing click count in an HTML button

Demo Code

ResultView the demo in separate window

<html>
   <head>
      <style>

.btnClass {//from   w w w .j av  a2  s.  c o  m
   width: 96px;
   height: 48px;
   font-size: 24px;
   background: #4FFF8F;
}

      </style> 
   </head>
   <body> 
      <h2>The Button Element</h2> 
      <button id="btn" class="btnClass">0</button> 
      <script>
    var btn = document.getElementById('btn');
    var i = 0;
    btn.onclick = function () {
        i++;
        btn.innerHTML = i;
    };

      </script>  
   </body>
</html>

Related Tutorials