Javascript Reference - HTML DOM cookie Property








The cookie property sets or gets all name/value pairs of cookies in the current document.

Browser Support

cookie Yes Yes Yes Yes Yes

Syntax

document.cookie

Return Value

A string containing the name/value pairs of cookies in the document.





Example

The following code shows how to get the cookies associated with the current document.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--  w w w.  j a  v  a  2s . com-->
<script>
function myFunction()
{
    var x=document.getElementById("demo");
    x.innerHTML="Cookies associated with this document: " + document.cookie;
}
</script>
</body>
</html>

The code above is rendered as follows: