carhartl/jquery-cookie — Issue #45: $.cookie('name', null) not deleting cookie one place, is another... ?
Author: thewatts
Created: 2012-01-20 00:08:17+00:00
State: open

So, I have duplicate code here.... just attached to two different selectors (based on where you are located on site).

**This code _will not work_ for the $.cookie('name', null) to delete cookie.**

```
$('a.campus-select').click(function(){
var $campus = $(this).attr('rel');

// set or delete cookie
if ($campus == "all") {
$.cookie('Campus', null); // TRYING TO DELETE COOKIE - BUT WONT HERE. WILL BELOW?
console.log("current campus is " + $campus);
console.log($.cookie('Campus'));
} else {
$.cookie('Campus', null);
// setCookie('Campus',$campus,365);
$.cookie('Campus', $campus, { expires: 365, path: '/' });
console.log("just set the cookie for /");
}
});
```

**This code _will work_ work for the $.cookie('name', null) to delete cookie.**

```
$('a.home-campus-select').click(function(){
var $campus = $(this).attr('rel');
var $update_links = $('ul.filter li a');

// set or delete cookie
if ($campus == "all") {
$.cookie('Campus', null); // BUT DELETING A COOKIE HERE WORKS... ?
console.log("current campus is " + $campus);
console.log($.cookie('Campus'));
} else {
$.cookie('Campus', null);
// setCookie('Campus',$campus,365);
$.cookie('Campus', $campus, { expires: 365, path: '/' });
console.log("just set the cookie for /");
}
});
```

I have literally copied and pasted the code into each other - they are nearly identical - yet - the top will not delete the cookie with $.cookie('Campus', null);

I may be completely missing this - and if so, that is fine :) I just want to know what I'm doing wrong - or if there is a bug!

If you want to see it in action: 2011.newlifechurch.tv

Working one is on the ** home page ** - bottom updates, you can see in the console. When clicking 'All' in the filter - you will see **null** show up (make sure you select a campus first!)

Then on the updates page (2011.newlifechurch.tv/updates) - if you do the same with the filters, you will see that it won't say 'null', instead saying a campus name.