Jquery set Cookie and Check

In this we set the cookie and then check it available or not. If available then what we want to do next to that.  By this we check the users comes again or not. On the basis of that we have several option to what to show them.


–       Jquery

–       Jquery Cookie Function


// global variable to check form hide or show
var opt;
// function that create the cookie on form submission when it is shown
show = function(){
// create the cookie name opt with value show1 and expire after 7 days
opt = jQuery.cookie("opt", "show1", { expire: 7, path: '/' });
// function that checks the cookie is set or not
function getCookie(opt) {
// set the opt value to variable
var nameEQ = opt + "=";
// split cookies
var ca = document.cookie.split(';');
// check all cookies one by one
for(var i=0;i < ca.length;i++) {
var c = ca[i];
// check the cookie value is not null
while (c.charAt(0)==' '){
c = c.substring(1,c.length);
// find the cookie with the condition we sets
if (c=='opt=show1'){
// after finding cookie what we want to do we set here, here we get the div and set to null
// then set the value what we want to show
document.getElementById('WFItem96692').innerHTML="new text";
// return data
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length,nameEQ.length + 4);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s