I want to remember with jquery the user’s choice using cookie.
I Installed the jquery.cookie plugin and it works grate, but the problem is that it’s working only if I put the script on the bottom of the html page, but if I put the code in an external file into document.ready, when I click on the element I got like two clicks, the if and the else is working together. What can be the solution?
# This is the html:
Hi
How are you?
# And this is the jquery:
$(function() {
$(‘.hi’).click(function() {
if ($.cookie(‘viewState’) === ‘off’ || !$.cookie(‘viewState’)) {
$(‘.how’).css(‘display’, ‘block’);
$.cookie(‘viewState’, ‘on’);
//return false;
} else {
$(‘.how’).css(‘display’, ‘none’);
$.cookie(‘viewState’, ‘off’);
//return false;
}
});
});