Clinton Green Clinton Green - 1 year ago 96
jQuery Question

js-cookie: How to use cookies in an if statement

I am using the js-cookie plugin and I want to know how to use it in an if statement. In my scenario I want to show a popup if the Cookie does not exist.


Cookies.set('adModalOpen', 'true', { expires: 8/24 });

If Statement

if ( !Cookies.get('adModalOpen') === 'true' ) {
// show popup

I've tried a using
=== Null
but that didn't work either.

Answer Source


if(!Cookies.get('adModalOpen')) {
 //show pop 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download