0

Please take a look at my website: moskah.nl

If you type something in the field, save and refresh. You wull notice the cookie holds the value. Now if you click on the list it will be deleted. Now try storing multiple list and remove them again. You will see the last clicked list item will not be deleted (on refresh)

I cant figure out why that is. Also I cant give you an example on jsfiddle becuase somehow it doesnt work there. Please look at the source code of website (its very small) to get an idea of what is going on.

This piece is holding the cookie value

    $('.fields a').click(function(e) {
        var text = $('#inputBox').val();
        var values = $.parseJSON($.cookie('myDemoCookie'));
        if (!values) {
            values = [];
        }
        values.push(text);

        $.cookie('myDemoCookie',JSON.stringify(values),{expires: 7, path: '/' });


$(".jq-text").append('<li><a href="' + text + '">' + text + '</a></li>');

        e.preventDefault();

    });

And this is for deleting the list:

$('.jq-text li').live('click', function(e) {
    var values = [];

    $(".jq-text").find('a').each(function(i, item) {

        values.push($(item).text());
    });


    $.cookie('myDemoCookie', JSON.stringify(values), {
        expires: 7
    });
    $(this).remove();
    e.preventDefault();


});

1 Answer 1

0

Try this: https://github.com/tantau-horia/jquery-SuperCookie

Set the cookie:

$.super_cookie().create("name_of_the_cookie",{name_field_1:"value1",name_field_2:"value2"});

Insert values:

$.super_cookie().add_value("name_of_the_cookie","name_field_3","value3");

Delete values:

$.super_cookie().remove_value("name_of_the_cookie","name_field_1"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.