Making a jQuery menu

Joined: 11/28/2008
User offline. Last seen 28 weeks 5 days ago.

I'm trying to use jQuery to make nested HTML lists expandable and collapsable, but need some help...

The code I have is currently running from a $(document).ready() function and as a result my menu/list is being reset at every page load (collapsed back to normal). How do I make my menu stay expanded between page loads?

Here's the code I'm using:

$(document).ready(function() {
  // Hide all child links by default
  $('#pondering-archives ul').hide();

  // Display child links when parent link is clicked
  $('#pondering-archives .title').click(function() {
    $(this).siblings('ul').slideToggle(500);
  });
});

Thanks!

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
User offline. Last seen 21 weeks 6 days ago.
cookies

If you want to store something like that in the browser between page loads a good way to do that is with a cookie. With a cookie you can set and get the current state of the menu and it will carry over between page loads.

You can find more details at http://plugins.jquery.com/project/Cookie

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com