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(); 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.
This worked for me:
function getCookieValue(cname) { // cname is the cookie name (foo) which value you are after var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } To get the value of a cookie, you can just call it's reference. For example:
$.cookie("foo", "somevalue"); alert($.cookie("foo")); Will alert:
somevalue