Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:50:49+00:00 2026-06-04T19:50:49+00:00

I’m trying to create a list of data-id’s and store them in a cookie,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:50:50+00:00Added an answer on June 4, 2026 at 7:50 pm

    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.

    // Get the portfolio ID from the query string
    var currentId = new RegExp("[\\?&]MYID=([^&#]*)").exec(location.search)[1]
    // Replace MYID in the line above with the name of your querystring parameter
    

    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.

    function get_cookie ( cookie_name )
    {
      var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
    
      if ( results )
        return ( unescape ( results[2] ) );
      else
        return null;
    }
    
    if (get_cookie('readPortfolios') == null) {
      // Extremely simplified implementation
      document.cookie = 'readPortfolios=' + currentId;
    }
    else {
      // We have a cookie already. We'll read it
      var ck = get_cookie('readPortfolios');
    
      // We want to add this page's portfolio Id
      ck += ',' + currentId;
    
      // We then want to save the cookie back
      document.cookie = 'readPortfolios=' + ck;
    }
    

    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:

    <ul id="myPortfolioList">
      <li id="data-id-1">Text One</li>
      <li id="data-id-2">Text Two</li>
      <li id="data-id-3">Text Three</li>
    </ul>
    

    First I need my cookie values, then I want to compare these to the Id values of my list items.

    var values = get_cookie('readPortfolios').split(',')
    
    $('#myPortfolioList li').each(function(){
      if ($.inArray(this.id, values) > -1) {
        console.info('Portfolio Item ' + this.id + ' has been visited.');
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.