Create, read, and erase cookies with jQuery

Agus Puryanto picture Agus Puryanto · Oct 21, 2009 · Viewed 637.8k times · Source

Somebody help me. How to create, read and erase some cookies with jQuery ?

Answer

Ramesh Soni picture Ramesh Soni · Oct 21, 2009

Use JavaScript Cookie plugin

Set a cookie

Cookies.set("example", "foo"); // Sample 1
Cookies.set("example", "foo", { expires: 7 }); // Sample 2
Cookies.set("example", "foo", { path: '/admin', expires: 7 }); // Sample 3

Get a cookie

alert( Cookies.get("example") );

Delete the cookie

Cookies.remove("example");
Cookies.remove('example', { path: '/admin' }) // Must specify path if used when setting.