I’m trying to create a list of data-id’s and store them in a cookie, so I can loop thru them later and manipulate them as needed. This needs to be done client-side, so I’m wanting to use jQuery Cookies.
Say I have a list of portfolio items with a unique data-id attribute associated with each item. When a user clicks into a single portfolio item, I need to store that specific data-id into a jQuery cookie, so I can reference it later.
What is the best way of going about this?
Edited
So you want to check which portfolio pages a user has already visited (NB: instead of cookies, you might also consider the HTML5 History API or localStorage).
When a user visits a page, you want to retrieve the portfolio ID from somewhere. That might be within a DOM element or it could be in the query string of the URL. I’m going to assume it’s the latter.
Ok, so we have our Id. Next we need to read any existing ones from our cookie. If the cookie doesn’t exist we need to create it.
So that’s our per-page stuff complete. Next we want to look through our list on the main page to see which pages have been visited.
Assuming you have a list that looks like the following:
First I need my cookie values, then I want to compare these to the Id values of my list items.