O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required