Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use cookies in JQuery

It is easy to use cookies in serverside like PHP,.NET...etc

I would like to use cookies for static website which is just HTML, CSS & JQuery .

Anybody know how to implement cookies in JQuery ?

like image 400
Mo. Avatar asked Mar 15 '12 13:03

Mo.


3 Answers

the jQuery Cookie plugin is one way to go:

https://github.com/carhartl/jquery-cookie

You use it like so:

$.cookie('cookie_name', 'value'); // to set

$.cookie('cookie_name'); // to get
like image 160
aletzo Avatar answered Oct 05 '22 13:10

aletzo


You can use this plugin

example: to set a cookie

$.cookie("example", "foo");
like image 28
Kimon Moutsakis Avatar answered Oct 05 '22 11:10

Kimon Moutsakis


You don't need a jQuery plugin, you can easily access cookies in JavaScript. Here's how: https://developer.mozilla.org/en/DOM/document.cookie

But maybe the plugins linked in the other answers will give you easier access.

like image 30
chiborg Avatar answered Oct 05 '22 13:10

chiborg