Thomas
Thomas

Reputation: 589

Count click on button or link and store in cookie

So here is the deal. I have a div I want to show the 3rd time the same user clicks a button. I want to store the clicks in a cookie and count the clicks. Then when the button is clicked for the 3rd time I want to show the div.

I use jquery on my site and already use this http://plugins.jquery.com/files/jquery.cookie.js.txt to set other cookies, but I must admit I am a javascript newbee to say the least

Upvotes: 1

Views: 4956

Answers (1)

alex
alex

Reputation: 490657

$('button').click(function() {
   var clickCount = parseInt($.cookie('clickCount'), 10);

   clickCount++;

   if (clickCount >= 3) {
       $('div').show();
   }

   $.cookie('clickCount', clickCount, { path: '/' });   

});

Upvotes: 6

Related Questions