Sunday, September 11, 2011

Click Counter with jQuery

Summary: Count every user click "click me!" link

<html>
  <head>
    <title>Click Counter</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript">
      // http://kuntoaji.blogspot.com
      $(function(){
          var total_click = 0;
          $("#clickMe").click(function(){
            total_click = total_click + 1;
            $("#counter").text("Total Click: " + total_click);
return false;
          });
        });
    </script>
  </head>
  <body>
    <div id="counter">Total Click: 0</div><br />
    <a id="clickMe" href="#">click me!</a>
  </body>
</html>

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...