JQuery update cookie value

I am using jquery cookie library to create cookie with jQuery. How can I update the cookie value? I need to create a new cookie, and if a cookie exists to update it. How can i do this? Code I received:

v.on('click', function(){ var d = $(this).attr('role'); if(d == 'yes') { glas = 'koristan.' }else { glas = 'nekoristan.' }; text = 'Ovaj komentar vam je bio ' + glas; //This part here create cookie if(id_u == 0){ $.cookie('010', id + '-' + d); } $.post('<?php echo base_url() ?>rating/rat_counter', {id : id, vote : d, id_u : id_u}, function(){ c.fadeOut('fast').empty().append('<p>' + text).hide().fadeIn('fast'); }); }) 
+7
source share
2 answers

To update a cookie, you need to create a cookie with the same name and different value.

Edit

To add a new value to the old ...

 //Im not familiar with this library but //I assume this syntax gets the cookie value. var oldCookieValue = $.cookie('010'); //Create new cookie with same name and concatenate the old and new desired value. $.cookie('010', oldCookieValue + "-" + id); 
+9
source

follow this link

http://www.electrictoolbox.com/jquery-cookies/

here you see everything you can do with cookies.

if you want to know if a cookie exists just use this

 if($.cookie("example") != null) { //cookie already exists } 
+1
source

All Articles