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 711725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:46:04+00:00 2026-05-14T04:46:04+00:00

Based on my previous question here and here , I found that I can

  • 0

Based on my previous question here and here, I found that I can set a cookie with javascript. I want to combine it with jquery to have a cookie state set for toggled table rows. I want to keep the hidden rows hidden upon reload.

Here is what I have achieved so far:

// Load cookies if any   
if(readCookie('togState')) {
       $('table#toggle tr.' + readCookie('togState')).hide();
    }

    $(function() {
        $('table#toggle tr.container').click(function() {
          var idTog = $(this).attr('id');
            $(this).toggleClass('off').nextAll('.' + idTog).toggle();
            setCookie('togState', idTog, 30);
            alert('Cookies: ' + readCookie('togState'));
        });

});

The parent: <tr id="parent-1" class="container">

The following children: <tr class="contained parent-1"> , etc

As you can see the cookie is read, but is not set upon browser refresh. What am I doing wrong?

What I want is hide any toggled rows (having their classes equal to their parent’s container ID), if the parent container is clicked, and so the cookie is set.

Any help would be very much appreciated. Thanks.

The source cookie I used for quick check:

function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    setCookie(name,"",-1);
}

UPDATE:

I have also tried each function to no luck:

$('table#toggle tr.' + readCookie('togState')).each(function() {
     $(this).hide();
   });

UPDATE 2:

If I place the check inside jquery (I used hide()), it works, but only for a single cookie. So the actual problem now is how to keep more cookies for more parent rows?

  • 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-05-14T04:46:05+00:00Added an answer on May 14, 2026 at 4:46 am

    If you’re using the setCookie() function from this answer, you’re setting your cookie to have a lifetime of 30 seconds. That’s probably not long enough for your requirements, and you should probably look at increasing it ever so slightly. 🙂

    EDIT Re: your question edit – If you’re trying to set multiple cookies, you’ll have a problem with the following line:

    document.cookie = name+"="+value+expires+"; path=/";
    

    Here, you’re overwriting the cookie property every time you call setCookie(). If you want to set multiple cookies, you need to prepend/append a new name/value pair to the string with each call to setCookie()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

based my previous question asked here: Jquery Filter List DIVs via checkboxes i got
I have a bit of a problem here. Based on my previous question asked
I have a non ode function that calculates based on the previous time step
Based on a previous question I posed (see here ) and the following msdn
Based off of a previous question I asked, which @Andrie answered, I have a
This question is built off of this previous question 'here' I want to make
This question is based on a previous similar question. I have the following equation
Based on my previous question here my new concern is how do I unit
Following up on a previous question, here is my general class structure.. Combine Elements
Based on a previous question and with a lot of help from Damir Sudarevic

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.