How to set a cookie and expire it in 30 days

Include the following script. Or you can grab the latest version at the cdnjs website.

```
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.2.1/js.cookie.min.js" integrity="sha512-Meww2sXqNHxI1+5Dyh/9KAtvI9RZSA4c1K2k5iL02oiPO/RH3Q30L3M1albtqMg50u4gRTYdV4EXOQqXEI336A==" crossorigin="anonymous"></script>
```

Using js-cookie

Set a cookie

```
Cookies.set('name', 'value')
```

Set a cookie with an expiry of 30 days

```
Cookies.set('name', 'value', { expires: 30 })
```

So here in this example the cookie called name, with the value of value will expire in the browser after 30 days. 

Further Documentation on JS Cookie
https://github.com/js-cookie/js-cookie?utm_source=cdnjs&utm_medium=cdnjs_link&utm_campaign=cdnjs_library 

Get the latest CDNJS version of this code here:
https://cdnjs.com/libraries/js-cookie 

Other Items in javascript

No Items Found.

Add Comment
Type in a Nick Name here
 
Page Views

This page has been viewed 130 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
Even if you fall on your face, you're still moving forward.
Victor Kiam