Clinton Green
Clinton Green

Reputation: 9977

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.

Cookie

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.

Upvotes: 1

Views: 652

Answers (1)

Jian Wang
Jian Wang

Reputation: 94

just

if(!Cookies.get('adModalOpen')) {
 //show pop 
}

Upvotes: 2

Related Questions