JavaScript Code

How to get all cookies for the web page?

Tutorials using JS

Get all cookies

In this tutorial, you shall learn how to get all cookies for the document/web-page.


To get all the cookies currently present for the document, use document.cookie. cookie property returns a semicolon separated list of name-value pairs as shown in the following.

key1=value1; key2=value2; key3=value3


In the following program, we get the cookies string using JavaScript, and then display this value in div#output element.

<!DOCTYPE html>
<div id="output"></div>

var cookies = document.cookie;
document.getElementById('output').innerHTML = cookies;


Copyright @2022