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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:36:03+00:00 2026-05-24T12:36:03+00:00

I just have a menu withe blocks which can be hidden. In order to

  • 0

I just have a menu withe blocks which can be hidden. In order to memorize their state during the visit, I decided to use jQuery.cookie()
My code is very basic :

jQuery(document).ready(function(){
    $(".titre_acordeon").next().hide();
    $(".titre_acordeon").each(function () {
        jQuery.cookie($(this).parent().attr("id"),false, {path: "/"});
    });
    $(".titre_acordeon_0").next().show();
    $(".titre_acordeon_0").each(function () {
        jQuery.cookie($(this).parent().attr("id"),true, {path: "/"});
    });
});
jQuery(document).ready(function(){
    $(".titre_acordeon, .titre_acordeon_0").click(function() {
        $(this).next().toggle("medium");
        var id = $(this).parent().attr("id");
        var valeur_id = jQuery.cookie(id);
        alert(valeur_id)
        if ( valeur_id == true)
        {
            jQuery.cookie(id, false, {path: "/"});
        }
        else if ( valeur_id == false)
        {
            jQuery.cookie(id, true, {path: "/"});
        }
        alert(jQuery.cookie(id))
    });
});

”
As not excepted, the cookie values never change : the show/hide works, if I change “if ( valeur_id == true)” by “if (valeur_id)”, the cookies change but only once

I’m so desperate! this should be easyyy !

thx for reading 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-05-24T12:36:03+00:00Added an answer on May 24, 2026 at 12:36 pm

    If you are using this “plugin”

    https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js

    Your problem is that you are writing a boolean to your cookie, which is translated to a string on write to the cookie. Reading back from the cookie does not translate in reverse. So no matter whether you put true or false in the cookie, your check for

    if ( valeur_id == true)
    

    always evaluates to boolean true. This is because "true" and "false" are both strings which evaluate to “truthy” in such a check.

    If you want to stick with that library, you should write strings to the cookie and expect strings on read.

    $.cookie( 'cookieName', 'true' );
    

    And:

    if ( $.cookie( 'cookieName' ) === 'true' )
    

    Important note:

    As an aside, if you run the entire code sample on your page, you’ll never see the result of the clicking on read of the cookie when you reload the page. Your first block of code overwrites whatever was set by clicks on previous page loads.

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

Sidebar

Related Questions

I have just added a Telerik menu to my MVC application. I also have
I've recently decided that I just have to finally learn C/C++, and there is
I recall I have read about a parser which you just have to feed
You can't use wildcards in menu paths? A quick summary of my problem (which
I have a drop down menu that's working just fine in Chrome and Safari,
I just have started to learn Haskell and combine reading books and tutorials with
I just have an XP machine, and i want to play around using CC.NET.
I just have a quick question about how to get the length of a
Currently I just have a file like this that I manually parse into a
So I have site list on certain pages that basically just have links to

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.