• function

jQuery.cookie jquerypp/dom/cookie

 

jQuery.cookie(name, [value, ] [options])

Parameters

  1. name {String}Optional

    The name of the cookie.

  2. value {String}Optional

    The value of the cookie.

  3. options {Object}Optional

    An object literal containing key/value pairs to provide optional cookie attributes. Values can be:

    • expires {Integer | Date}

      Either an integer specifying the expiration date from now on in days or a Date object. If a negative value is specified (e.g. a date in the past), the cookie will be deleted. If set to null or omitted, the cookie will be a session cookie and will not be retained when the the browser exits.

    • domain {String}

      The domain name

    • path {String}

      The value of the path atribute of the cookie (default: path of page that created the cookie).

    • secure {Boolean}

      If true, the secure attribute of the cookie will be set and the cookie transmission will require a secure protocol (like HTTPS).

Returns

{String}

the value of the cookie or {undefined} when setting the cookie.

jQuery.cookie(name, [value], [options]) lets you create, read and remove cookies. It is the jQuery cookie plugin written by Klaus Hartl and dual licensed under the MIT and GPL licenses.

Examples

Set the value of a cookie.

 $.cookie('the_cookie', 'the_value');

Create a cookie with all available options.

 $.cookie('the_cookie', 'the_value', {
     expires: 7,
     path: '/',
     domain: 'jquery.com',
     secure: true
 });

Create a session cookie.

 $.cookie('the_cookie', 'the_value');

Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain used when the cookie was set.

 $.cookie('the_cookie', null);

Get the value of a cookie.

 $.cookie('the_cookie');