Counter Button


Description : It is a javascript based button counter. In this we declare global variable counter which counts the button clicks. The updated counter value is displayed as a text in heading.

Example:

0





Html Code
 <!DOCTYPE html>  
 <html>  
 <head>  
 <title>Counter Button</title>  
 <script>  
 var counter = 0;  
 function countBtnClicks() {  
  counter = counter + 1;  
   document.getElementById("txtBtnCount").innerHTML = counter;  
 }  
 </script>  
 </head>  
 <body>  
 <h2 id="txtBtnCount">0</h2>  
 <button onclick="countBtnClicks()">Counter Button</button>  
 </body>  
 </html>  

Comments

Popular posts from this blog

File handling

Getting started with android app development

How to create android Text To Speech app