Getting a Cookie Value from the Browser

function getCookie(name) {   var cArr = document.cookie.split(';');   for(var i=0;i < cArr.length;i++) {     var cookie = cArr[i].split("=",2);     cookie[0] = cookie[0].replace(/^\s+/,"");     if (cookie[0] == name){ return cookie; }   } }

To get the value of the cookie, split the document.cookie value using the ; character, and then iterate through the resulting array until you find the name you are looking for.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.