jQuery.cookies is a general purpose cookie library with several distinguishing design features:
Ability to specify defaults for domain, path, and “permanent” cookie expiration date
Presumes that most cookies are intended as either session scoped or permanent. Most web developers don’t want to set expiration dates manually.
Ability to easily manage sub-values within top-level cookies.
Usage
jQuery.cookies allows setting a default path, domain, and expiration date (for permanent cookies) for all usages of its API where these values are not explicitly specified. To set defaults, use $.cookies.setDefaults(). The options include:
path: Sets the default path. By default, it is “/”.
domain: Sets the default domain. By default, it is “”.
permanentDate: Sets the expiration date to use for cookies you declare “permanent”. By default, it is 1 year into the future. This should be specified as a UTC date.
Setting and getting cookies
Here’s a basic example of setting and getting a top-level cookie:
Some more examples of setting cookies:
Working with sub values
You can use an object to specify sub-values for a cookie:
Removing cookies
To remove/delete a cookie, use jQuery.cookie.remove():