I just recently started trying to use the cookie library js-cookie:
Found here: https://github.com/js-cookie/js-cookie
I can't seem to determine whether my cookies are being set or read correctly. The main goal is to read if a checkbox is checked, create a cookie and use that on another page to change some elements.
Here's how I attempted setting the cookie:
$('#food').click(function() {
if ($(this).is(':checked')){
Cookies.set('food', 'true');
}
else{
Cookies.remove('food');
}
});
It properly reads the checkbox being checked on click, so I know it is at least reaching the cookie set.
For reading the cookie value:
if(Cookies.get('food') === 'true'){
$('#food').css("color", "#198a80");
}
I followed the documentation on the repository page for setting and it looks correct. I assumed reading the cookie just passed the value portion as a normal variable and it could be compared like normal, but the code just does nothing, so I guessed the problem was either with the setting or reading of the cookie.