back to Overview


Returns the cookie with the given name.
Complete distribution only, not available in stand-alone modules.

Syntax Variants

$.getCookie(name, dontUnescape)


the name of the cookie. Should consist of alphanumeric characters, percentage, minus and underscore only, as it will not be escaped. You may want to escape the name using encodeURIComponent() if it contains any other characters.
dontUnescape (optional)
if set and true, the value will be returned unescaped. Use this parameter only if the value has been encoded in a special way and not with the standard JavaScript encode() method.
(return value)
the value of the cookie, or null if not found. Unless dontUnescape has been set, the value has been unescaped using JavaScript's unescape() function.


Returns the cookie with the given name.


Reads the existing cookie 'numberOfVisits' and displays the number in the element 'myCounter':

var visits = $.getCookie('numberOfVisits');
if (!visits)    // check whether cookie set. Null if not
    $('#myCounter').set('innerHML', 'Your first visit.');
    $('#myCounter').set('innerHTML', 'Visit No ' + visits);

See also..


comments powered by Disqus

back to Overview