0

I have a script which allows to save input value as a list: JsFiddle

So now Im trying to make an event which will delete a certain list if clicked on, of course the cookie should be destroyed. So I tried:

$('.jq-text li').click(function(e) {

$.cookie("myDemoCookie", null);

 });

This should destroy the cookie but it doesn't...

Youss
  • 4,196
  • 12
  • 55
  • 109

1 Answers1

1

I saw your jsfiddle code, you are creating cookie with a path, so you'll have to specify path when deleting cookie.

Make sure you have read documentation of $.cookie.

@example $.cookie('the_cookie', null);

@desc Delete a cookie by passing null as value. 
 Keep in mind that you have to use the same path 
 and domain used when the cookie was set.`

Try following code:

$.cookie('myDemoCookie', null, { path: '/' });
Zain Shaikh
  • 6,013
  • 6
  • 41
  • 66
  • I tried that `$.cookie('myDemoCookie',JSON.stringify(values),{expires: 7, path: '/' }, null);` Doesnt work – Youss Sep 27 '12 at 08:38
  • Thanks:) do you have any idea why this doesn't work `$(this).cookie('myDemoCookie', null, { path: '/' });` Because it seems your code deletes all the list and not the one clicked on – Youss Sep 27 '12 at 08:48
  • 1
    I think you do not need to delete cookie this time, you need to update. I have done that for you :) check out this demo: http://jsfiddle.net/zainshaikh/dx6CN/9/ – Zain Shaikh Sep 27 '12 at 09:01
  • Thanks for sticking around:) Your code is not working 100% but I think its because of JsFiddle(does not handle cookie very well) not because of code – Youss Sep 27 '12 at 09:06
  • may be its browser compatibility issue, I was testing with chrome. – Zain Shaikh Sep 27 '12 at 09:07
  • I work with chrome to, but I experienced cookie problems with JsFiddle in other coding. – Youss Sep 27 '12 at 09:14