Demo

Demos are largely unstyled to give developers a better idea of how the plugin can drop into a new or existing project.

Set Cookie

Get Cookie

Erase Cookie

View All Demos

Using Cookie

Main

cookie.js

Dependencies

jQuery
core.js

Basic

To create a new cookie, or update an existing one, simply pass the key and value as the first and second parameters, respectively:

// Set cookie
$.cookie(key, value);

To return a cookie's value pass the key as the only parameter:

// Get Cookie
var value = $.cookie(key);

To erase an existing cookie, set it to null:

// Erase Cookie
$.cookie(key, null);

Options

Set instance options by passing a valid object at initialization, or to the public defaults method.

Name Type Default Description
domain string   Cookie domain
expires int 604800000 Time until cookie expires
path string   Cookie path

Methods

Methods are publicly available, unless otherwise stated.

create

Creates a cookie.

$.cookie(key, value, options);

Parameters

Name Type Default Description
key string   Cookie key
value string   Cookie value
options object   Options object

erase

Deletes a cookie.

$.cookie(key, null);

Parameters

Name Type Default Description
key string   Cookie key

read

Returns a cookie's value, or null.

var value = $.cookie(key);

Parameters

Name Type Default Description
key string   Cookie key