I am missing something really simple...
I have a button that sets a cookie:
<button id="gotit" >Got it</button>
JS:
$('#gotit').click(function () {
setCookie("gotIt", 'True', 30);
});
And I a checkGetIt()
function with a simple if else:
function checkGetIt() {
var gotIt = getCookie("gotIt");
if (gotIt === "") {
console.log('no such cookie'); // should do this until button pressed
} else {
console.log('cookie exists'); // this displays all the time, which is wrong
}
}
checkGetIt();
var z = document.cookie;
console.log('existing cookies: ' + z);
But I always get console.log('cookie exists');
even if console.log('existing cookies: ' + z);
gives me nothing before the button click.
setCookie() and getCookie() are generic functions that worked for me before.