HTML DOM cookie Property
Example
Get the cookies associated with the current document:
var x = document.cookie;
Try it yourself »
Definition and Usage
The cookie property sets or returns all name/value pairs of cookies in the current document.
For more information about cookies, read our JavaScript Cookies Tutorial.
Browser Support
Property | |||||
---|---|---|---|---|---|
cookie | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the cookie property:
document.cookie
Set the cookie property:
document.cookie=newCookie
Property Values
Parameter | Description |
---|---|
newCookie |
A String that specifies a semicolon-separated list of name=value pairs, or one
name=value pair together with any of the following, optional, values:
An example of creating a cookie:
Note: The value of a cookie cannot contain commas,
semicolons or whitespaces. However, you can use the
encodeURIComponent() method to ensure
that they don't |
Technical Details
Return Value: | A String, containing the name/value pairs of cookies in the document |
---|---|
DOM Version | Core Level 2 Document Object |
Related Pages
JavaScript Tutorial: JavaScript Cookies
Document Object