I am trying to create a jQuery based style switcher which changes the body class depending on the number of visits ot the website.
The problem I am having is that the code I am using changes the class on every page load rather than per visit. The number of visits also alerts a NaN value in Safari.
Do I need to specify a session time? How can this be achieved? I am using the jquery.cookie plugin, here is the code:
if(!$.cookie('visits')){
$.cookie('visits',1, {expires: 30});
}
$.cookie('visits', (parseInt($.cookie('visits')) + 1), {expires: 30})
//will expire after 30 days
if(parseInt($.cookie('visits')) == 2){
$('body').removeClass().addClass('blue');
} else if (parseInt($.cookie('visits')) == 3){
$('body').removeClass().addClass('green');
} else if (parseInt($.cookie('visits')) == 4){
$('body').removeClass().addClass('purple');
} else if (parseInt($.cookie('visits')) == 5){
$('body').removeClass().addClass('red');
} else if (parseInt($.cookie('visits')) > 5){
$.cookie('visits', 1);
};
Help appreciated :)