Change number every time when clicking - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Change number every time when clicking

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head></head>
   <body translate="no"> 
      <center> 
         <span id="timesClicked">0</span> 
      </center> 
      <button type="button" class="btn btn-default" onclick="javascript:btnClick()">Click</button> 
      <script>
      var timesClicked = 0;//  w w  w .  ja  v  a 2 s. c  om
 function btnClick(){
    timesClicked ++;
    document.getElementById('timesClicked').innerHTML = timesClicked;
    return true
}
    
      </script>  
   </body>
</html>

Related Tutorials