jQuery Menu Help


I’m very new to javascipt/jQuery but have put together this menu


I’ve got it to keep the menu items open when you change page but I need the menu to stay open when you’ve clicked a sub-menu item as it currently closes it.

Any ideas?

Thank you

Hi there,

Ideally, you should not be using JavaScript to remember a navigation’s state.

How are youincluing the navigation into your page?
Via PHP or is it hard-coded?

The navigation is hard coded into the page.

Is there another way to remember a navigation state? WOuld it be with css?

I’ve made you a simple example demonstrating how to do this.
You basically apply an “active” class to your active menu points and style them differently than your non-active ones.

Have a look at the source of my demo to see the code and let me know if you have any questions.


Thank you very much for the demo, it’s a good piece of code to work from!

So the jQuery is just running the menu animations?

Would it be possible to keep the menu open say when I click Page 1?

Thanks again!

That’s right.
HTTP is a stateless protocol, so individual web pages (and by definition the JS they execute) have no concept of an action which was taken on a previous/different page.
You can use client-side storage to persist data, but in this case, it is better to just apply a class and style accordingly.

Yes, you could add the appropriate class declaration to page 1 (look at the source code of the demo).
However, if this is something you want to do, then I would alter the class names for example “open” is better than “active”.

Brilliant! You’ve been a great help!

I’m going to have a play around with the source code and see what I can come up with!

I’d +rep you but doesn’t seem this forum uses it!

Thanks again!


No problem :slight_smile:

This has been discussed and will actually be introduced sometime in the future.
In the meantime, you could show your appreciation by voting at the end of year awards which should be going live next week.

Well I’ll vote for you in the awards then :slight_smile:

Thanks again!