Cookie in client side using jQuery

Setting a cookie using jQuery is quite easy. This can be done with the help of jQuery Cookie Plugin. $.cookie() is used to set and get a value from a cookie. Download the "jquery.cookie.js" from plugins.jquery.com

Setting a Cookie:

$.cookie("CodeExpertz", "active", { path: '/' });

where, CodeExpertz is the cookie name

           active is the value stored

           { path: '/' } makes the cookie available over the domain (i.e to all the pages), You can restrict it ro few pages also

Getting a value from a Cookie:

$.cookie("CodeExpertz"); // this returns the value stored in the cookie "CodeExpertz" --> active

 

Category: