Search code examples
javascriptjquerycookies

Retrieve jQuery Cookie value


Example, I have this cookie:

$.cookie("foo", "500", { path: '/', expires: 365 });

How do I get the value of that cookie and put it into a variable?

For example (I know this is not correct):

var foo = $.cookie("foo").val();

Solution

  • It's just var foo = $.cookie("foo").

    There's no need for a .val() call as you're not accessing the value of a DOM element.