0

I am currently using this JQuery cookie plugin https://github.com/js-cookie/js-cookie and it is working for just single cookie value but i want it to work for multiple dynamic values stored in as an array.

For example, i have a list of the products in a page and i am showing "save products" link on each products. I want, clicking on the save button to store an id of the products in same cookies so i can retrieve all the values and display in a separate page.

I will appreciate if you can just show me how to store values in a cookies as an array i will do the rest.

HTML:

<ul>
 <li id="product1">product 1 <a>Save Products</a></li>
 <li id="product2">product 2 <a>Save Products</a></li>
</ul>

JQUERY:

$('ul li a').each(function(){
 $('this').click(function(){
  Cookies.set('SavedProducts', { foo: 'bar' });
 });
});
1
  • so store an array of the items clicked. var z = []; z.push("aaaa"); what trouble are you having? Commented Apr 11, 2017 at 22:54

1 Answer 1

0

In my opinion, since orignal cookie only supports TEXT based saving, You should serialize the arrays/tuple before storing as cookie.

Please Refer the following link. how to store an array in jquery cookie?

Good Luck

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.