JavaScript Counter


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. </head>
  6. <body>
  7.  
  8. <p id="foo" style="font-size: 15em; font-weight: bold; margin-top: 0px; text-align: center;">
  9. 1
  10. </p>
  11.  
  12. <script>
  13. // Go...
  14. var e = document.getElementById("foo");
  15.  
  16. // Set the interval
  17. setInterval(function () {
  18.  
  19. // Increment
  20. e.innerHTML -= -1;
  21.  
  22. return;
  23. }, 100, e);
  24. // Make sure to pass the element along with the function.
  25. // A value of 0 for the timeout will make the browser go as fast as it can. (NOT RECOMMENDED)
  26. </script>
  27. </body>
  28. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.