Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use this jQuery plugin to delete a cookie?

First, to show the cookie, I used code from electrictoolbox.com.

Then I made a form to add some cookie:

<form class="cokies" method="post">
<input class="query" name="q" type="text" />
<input type="submit" name="save" value="saving">
<a>Delete Cookies</a>
</form>
$(document).ready(function(){
$('.cokies a').click(function(){
    $.cookie('q', null);
});

remember('[name=q]');

This function is from komodomedia.com:

function remember( selector ){
    $(selector).each(function(){
        //if this item has been cookied, restore it
        var name = $(this).attr('name');
        if( $.cookie( name ) ){
            $(this).val( $.cookie(name) );
        }

        //assign a change function to the item to cookie it
        $(this).change(function(){
            $.cookie(name, $(this).val(), { path: '/', expires: 365 });
        });
    });
}

The problem is, I can't work out how to delete a cookie.

like image 824
Agus Puryanto Avatar asked Oct 26 '09 08:10

Agus Puryanto


1 Answers

To delete the cookie, simply set the expires: to a negative integer value.

example:

$.cookie(name, $(this).val(), { path: '/', expires: -5 });

like image 105
mauris Avatar answered Oct 01 '22 21:10

mauris