I apologize, my previous code was incorrect, here is the full code:
Code:
<!DOCTYPE html>
<html>
<head>
<script>
function setCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(";");
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==" ") c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
count = getCookie("count");
if(count == false) {
setCookie("count", 0, 7);
}
function tracker(i) {
if(i == 1) {
setCookie("count", count++, 7);
document.getElementById("count").innerHTML=count;
}
}
</script>
</head>
<body>
<button onclick="tracker(1)">Hit Me</button>
<div id="count"></div>
</body>
</html>
Feel free to click on the button as much as you want, it will continue to increment as you press the button.
You can also use jQuery cookie which is much simpler, but I think learning JavaScript first is better.