How To Set, Get And Delete Cookies With jQuery

Prerequisite Plugin
Get the plugin: http://plugins.jquery.com/project/cookie
How-To
Set a cookie: jQuery.cookie("myCookie", 1);
Get a cookie: jQuery.cookie("myCookie");
Delete a cookie: jQuery.cookie("myCookie", null);
Set expiration in days: jQuery.cookie("myCookie", 1, { expires : 10 });
If the expires option is omitted, then the cookie becomes a session cookie, and is deleted when the browser exists.
OPTIONS
jQuery.cookie("myCookie", 1, {
expires : 10, //expires in 10 days
path : '/', //The value of the path atribute of the cookie
//(default: path of page that created the cookie).
domain : 'jquery.com' //The value of the domain attribute of the cookie
//(default: domain of page that created the cookie).
secure : true //If set to true the secure attribute of the cookie
//will be set and the cookie transmission will
//require a secure protocol (defaults to false).
});
Leave Your Comment
All fields marked with "*" are required.