I am using the "Cookie Plugin" by Klaus Hartl to add or update cookies at $(document).ready
. I have another event that is supposed to iterate all the cookies and do something with the value of each cookie. How can I iterate over the collection of cookies and get the id and value of each?
I'm thinking something like this:
$.cookie.each(function(id, value) {
alert('ID='+id+' VAL='+value);
});
If you just want to look at the cookies it's not that hard without an extra plugin:
$.each(document.cookie.split(/; */), function() {
var splitCookie = this.split('=');
// name is splitCookie[0], value is splitCookie[1]
});
well it's rather easy in plain javascript:
var keyValuePairs = document.cookie.split(';');
for(var i = 0; i < keyValuePairs.length; i++) {
var name = keyValuePairs[i].substring(0, keyValuePairs[i].indexOf('='));
var value = keyValuePairs[i].substring(keyValuePairs[i].indexOf('=')+1);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With