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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:38:53+00:00 2026-05-28T00:38:53+00:00

I have cobbled the below together in my (very) humble jQuery hackish way: $(.toggle_container).hide();

  • 0

I have cobbled the below together in my (very) humble jQuery hackish way:

$(".toggle_container").hide();
                $(".trigger a").addClass("close");
                $(".trigger a").click(function() {
                $(".toggle_container").slideUp('200','swing');
                 $(".trigger a").removeClass("open").addClass("close");
                    if     ($(this).next(".toggle_container").is(":hidden")) {
                            $(this).next(".toggle_container").stop(true,false).slideToggle('200','swing');

                        }
                });

jsfiddle is here: http://jsfiddle.net/FWzWu/8/

I have never used the jquery cookie plugin, but would like to use it now to remember the users menu state from page to page. Using the github plugin here: https://github.com/carhartl/jquery-cookie

Any help is most appreciated!
Thanks!

  • 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-28T00:38:54+00:00Added an answer on May 28, 2026 at 12:38 am

    A first stab (I added a call to event.preventDefault() to stop the default anchor action from happening on click – you may need to remove this).

    It could do with some cleaning up, for example it would be good to take advantage of event delegation to capture the click event on anchor elements, hopefully it conveys how to use the plugin and where to use it.

     $(function () {   
    
        // give each container a unique class
        var containers = $("ul.toggle_container").hide().each(function (i,v) {
            $(this).addClass('container_' + i);       
        });
    
        var value = $.cookie('toggled_container');     
    
        // if we have a value in the cookie, use it to show that container
        if (value) {
            $('ul.' + value).show();
        }
    
        var anchors = $("li.trigger a");
    
        anchors.addClass("close").click(function() {
            containers.slideUp('200','swing');
            anchors.removeClass("open").addClass("close");
            var nextContainer = $(this).next("ul.toggle_container");
            if (nextContainer.is(":hidden")) {
                // capture the unique class that we have given the container
                $.cookie('toggled_container', nextContainer.attr('class').match(/container_\d+/));
                nextContainer.stop(true,false).slideToggle('200','swing');
            }
        });
    });
    

    Obviously, this solution assumes that your containers are never going to change in number and order; if they do, the wrong container will end up being expanded on page load 🙂

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

Sidebar

Related Questions

I have cobbled together a class that checks links. It works but it is
OK, so I have a cursor adapter that I cobbled together from various source
I have cobbled together a form due to some oddities in my code and
I have cobbled together some scripts from various internet sources to get a form
This much I have already cobbled together (thanks to Stack Overflowers): I have a
I'm trying to test a small PostgreSQL setup, so I cobbled together a quick
I've cobbled together a simple game loop, mostly using the techniques that seem be
I've built a very basic jQuery plugin that essentially positions a sprite image left
First, the prior situation: We have this project with a one-click build script. It's
Have just started using Google Chrome , and noticed in parts of our site,

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.