Get cookie value using cookie name Javascript / jQuery

Use cookie name to get cookie value, pass cookie name in function it will return cookie value.

getCookie(cookieName)
// read cookie data
function getCookie(cookiename) 
{
    // Get name followed by anything except a semicolon
    var cookiestring=RegExp(""+cookiename+"[^;]+").exec(document.cookie);
    // Return everything after the equal sign, or an empty string if the cookie name not found
    return unescape(!!cookiestring ? cookiestring.toString().replace(/^[^=]+./,"") : "");
}

Read: Create, Read and Delete cookie Javascript / jQuery

Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Yes0
No0
Harinder Singh

Harinder Singh

My name is Harinder Singh and I specialize in Software industry. I consider myself as a life learner. I love learning new concepts, embracing new ideas and reading and searching for innovation.