Create, Update and Delete Cookies using Jquery

Manivannan Murugavel
1 min readSep 22, 2017

Step1:

Download Jquery and Jquery Cookie js from i mentined URL
Jquery:
http://code.jquery.com/jquery-1.9.0.min.js
Jquery Cookie
https://raw.githubusercontent.com/ManivannanMurugavel/QuestionandAnswer/master/static/js/js.cookie.js

Step2:

Try the Code

Basic Usage

  1. Create a cookie, valid across the entire site:
    Cookies.set(‘name’, ‘value’);
  2. Create a cookie that expires 7 days from now, valid across the entire site:
    Cookies.set(‘name’, ‘value’, { expires: 7 });
  3. Create an expiring cookie, valid to the path of the current page:
    Cookies.set(‘name’, ‘value’, { expires: 7, path: ‘’ });
  4. Read cookie:
    Cookies.get(‘name’); // => ‘value’
    Cookies.get(‘nothing’); // => undefined
  5. Read all visible cookies:
    Cookies.get(); // => { name: ‘value’ }
  6. Delete cookie:
    Cookies.remove(‘name’);
  7. Delete a cookie valid to the path of the current page:
    Cookies.set(‘name’, ‘value’, { path: ‘’ });
    Cookies.remove(‘name’); // fail!
    Cookies.remove(‘name’, { path: ‘’ }); // removed!
    IMPORTANT! when deleting a cookie, you must pass the exact same path and domain attributes that was used to set the cookie, unless you’re relying on the default attributes.
    Note: Removing unexisting cookie does not raise any exception nor return any value

Know Further Details

https://github.com/js-cookie/js-cookie

--

--