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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:46:43+00:00 2026-05-16T10:46:43+00:00

I have the following code (Yes I know it’s quite long winded, but I

  • 0

I have the following code (Yes I know it’s quite long winded, but I want to keep it as much the same as possible)

Hopefully it will make sense, but essentially what I want to do is when a user clicks one of the toggles it will create the relevant cookie and set its value to “Open” and then when they click it again it remove the cookie. And vice versa depending on whether the panel was open or not. So I’m trying to get the cookies to be created and removed in time with the toggle.

How do I do this? Thanks.

$("div#FilterType div.PanelContent ul").hide();
$("div#FilterLevel div.PanelContent ul").hide();
$("div#FilterAge div.PanelContent ul").hide();
$("div#FilterCategory div.PanelContent ul").hide();

$("div#FilterArea div.PanelContent ul").show();
$("div#FilterArea div.PanelContent p").hide();
$("div#FilterArea div.PanelContent div.MapPanel").show();
$("div#FilterArea div.PanelHead h2 span").addClass("selected");

$("div.Filter div.PanelHead h2").attr('title', 'Toggle Panel');

$("div#FilterType div.PanelHead").click(function (e) {
    $("div#FilterType div.PanelContent ul").slideToggle('fast');
    $("div#FilterType div.PanelContent p").slideToggle('fast');
    $("div#FilterType div.PanelHead h2 span").toggleClass("selected");
    $.cookie('FilterType',
            $("div#FilterType div.PanelContent ul").is(":hidden") ? 'Collapsed' : 'Open');
});
$("div#FilterLevel div.PanelHead").click(function (e) {
    $("div#FilterLevel div.PanelContent ul").slideToggle('fast');
    $("div#FilterLevel div.PanelContent p").slideToggle('fast');
    $("div#FilterLevel div.PanelHead h2 span").toggleClass("selected");
    $.cookie('FilterLevel',
            $("div#FilterLevel div.PanelContent ul").is(":hidden") ? 'Collapsed' : 'Open');

});
$("div#FilterAge div.PanelHead").click(function (e) {
    $("div#FilterAge div.PanelContent ul").slideToggle('fast');
    $("div#FilterAge div.PanelContent p").slideToggle('fast');
    $("div#FilterAge div.PanelHead h2 span").toggleClass("selected");
    $.cookie('FilterAge',
            $("div#FilterAge div.PanelContent ul").is(":hidden") ? 'Collapsed' : 'Open');
});
$("div#FilterArea div.PanelHead").click(function (e) {
    $("div#FilterArea div.PanelContent ul").slideToggle('fast');
    $("div#FilterArea div.PanelContent p").slideToggle('fast');
    $("div#FilterArea div.PanelContent div.MapPanel").slideToggle('fast');
    $("div#FilterArea div.PanelHead h2 span").toggleClass("selected");
    $.cookie('FilterArea',
            $("div#FilterArea div.PanelContent ul, div#FilterArea div.PanelContent div.MapPanel").is(":hidden") ? 'Collapsed' : 'Open');
});
$("div#FilterCategory div.PanelHead").click(function (e) {
    $("div#FilterCategory div.PanelContent ul").slideToggle('fast');
    $("div#FilterCategory div.PanelContent p").slideToggle('fast');
    $("div#FilterCategory div.PanelHead h2 span").toggleClass("selected");
    $.cookie('FilterCategory',
            $("div#FilterCategory div.PanelContent ul").is(":hidden") ? 'Collapsed' : 'Open');
});


// Checks the values of the cookies (if they exist) to open or close the panels

var FilterType = $.cookie('FilterType');
var FilterLevel = $.cookie('FilterLevel');
var FilterAge = $.cookie('FilterAge');
var FilterArea = $.cookie('FilterArea');
var FilterCategory = $.cookie('FilterCategory');

if (FilterType == 'Open')
{
    $("div#FilterType div.PanelContent ul").show();
    $("div#FilterType div.PanelContent p").hide();
    $("div#FilterType div.PanelHead h2 span").addClass("selected");
}
else
{
    $("div#FilterType div.PanelContent ul").hide();
    $("div#FilterType div.PanelContent p").show();
    $("div#FilterType div.PanelHead h2 span").removeClass("selected");
}

if (FilterLevel == 'Open')
{
    $("div#FilterLevel div.PanelContent ul").show();
    $("div#FilterLevel div.PanelContent p").hide();
    $("div#FilterLevel div.PanelHead h2 span").addClass("selected");
}
else
{
    $("div#FilterLevel div.PanelContent ul").hide();
    $("div#FilterLevel div.PanelContent p").show();
    $("div#FilterLevel div.PanelHead h2 span").removeClass("selected");
}

if (FilterAge == 'Open')
{
    $("div#FilterAge div.PanelContent ul").show();
    $("div#FilterAge div.PanelContent p").hide();
    $("div#FilterAge div.PanelHead h2 span").addClass("selected");
}
else
{
    $("div#FilterAge div.PanelContent ul").hide();
    $("div#FilterAge div.PanelContent p").show();
    $("div#FilterAge div.PanelHead h2 span").removeClass("selected");
}

if (FilterArea == 'Open')
{
    $("div#FilterArea div.PanelContent ul").show();
    $("div#FilterArea div.PanelContent p").hide();
    $("div#FilterArea div.PanelContent div.MapPanel").show();
    $("div#FilterArea div.PanelHead h2 span").addClass("selected");
}
else
{
    $("div#FilterArea div.PanelContent ul").hide();
    $("div#FilterArea div.PanelContent p").show();
    $("div#FilterArea div.PanelContent div.MapPanel").hide();
    $("div#FilterArea div.PanelHead h2 span").removeClass("selected");
}

if (FilterCategory == 'Open')
{
    $("div#FilterCategory div.PanelContent ul").show();
    $("div#FilterCategory div.PanelContent p").hide();
    $("div#FilterCategory div.PanelHead h2 span").addClass("selected");
}
else
{
    $("div#FilterCategory div.PanelContent ul").hide();
    $("div#FilterCategory div.PanelContent p").show();
    $("div#FilterCategory div.PanelHead h2 span").removeClass("selected");
}

EDIT:
I’ve looked into using something like this:

$.cookie('FilterType', 
                $("div#FilterType").is(":hidden") ? null : 'Open');

OR

$.cookie('FilterType',
                $("div#FilterType").is(":hidden") ? 'Collapsed' : 'Open');

Would something like that work? and would the null work or does it need to be a value like the second example? From testing it allows the cookie to be created with the value of ‘Open’ but when the user clicks it again it doesn’t change the value to the ‘Collapsed’.

Is this because of the .is(":hidden") part?

  • 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-16T10:46:44+00:00Added an answer on May 16, 2026 at 10:46 am

    Assuming you are using the jQuery cookie plugin, your code should work as expected.

    $.cookie('name', null);
    

    does effectively “delete” the cookie item. You should also specify appropriate expiration time so that the cookie values are persisted across browser sessions. e.g.

    $.cookie('the_cookie', 'the_value', { expires: 365 });
    

    A tip: you can use .toggle( showOrHide ) and .toggleClass( className, switch ) to simplify the code.

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

Sidebar

Related Questions

I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS site.
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have the following code snippet. $items['A'] = Test; $items['B'] = Test; $items['C'] =
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I have the following code: String inputFile = somefile.txt; FileInputStream in = new FileInputStream(inputFile);
I have the following code: ListBox.DataSource = DataSet.Tables(table_name).Select(some_criteria = match) ListBox.DisplayMember = name The
I have the following code making a GET request on a URL: $('#searchButton').click(function() {

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.