jQuery Cookie Tutorials

Cookies are data which let you store user information in web pages. They are often used to track users’ data to re-use on their next visits to a web page. Creating and deleting cookies with jQuery is really easy thanks to the js-cookie library.

JavaScript cookie is a simple, lightweight JavaScript API for handling cookies. You can download it here. It can work in all browsers, accept any character. It has no dependency, supports ES modules and AMD/CommonJS with custom encoding/decoding.

Init the plugin via CDN

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js.cookie.min.js"></script>

Create a cookie

Cookies.set('website', 'TL Templates');
//create a cookie which expires 15 days from now and works for all pages
Cookies.set('website', 'TL Templates', { expires: 15 });
//create a cookie which expires 15 days from now and works for certain page
Cookies.set('website', 'TL Templates', { expires: 15, path: '/test' });

Read cookie data

Get all cookies

Cookies.get();

Get specific cookie

Cookies.get('website'); //output: 'TL Templates'
Cookies.get('some_cookie'); //output: undefined

Delete a cookie

Cookies.remove('website');

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close