How to stop menu resetting when switching pages?

I have an accordian css menu that resets to default (all closed) state when the user clicks a link from it.
Is it possible to keep the menu in it’s current state (open) to where the user was when the new page opens?

You can see what I mean here:

There are only 2 links that work:
Myths & Legends > Bedd Gelert
Myths & Legends > St. Gelert

Thanks for any help :slight_smile:


This menu has been kicking my butt all day.
Finally I think I have it under control:
Menu has changed a little,. (from post above)

History> Bedd Gelert
History> St. Gelert

But the issue remains with the menu going to original state of closed when a link is clicked and a new page is opened.

Any ideas would be appreciated.


Hi @rocatah, you can store the index of the currently active item to the session storage, and check for that index on page load; like e.g.

const current = sessionStorage.current
const items = $('#accordian > ul > li')
const subs = items.find('ul').hide()

if (typeof current !== 'undefined') {
} {
  $('ul', this).show()
  sessionStorage.current = $(this).index()


PS: In your original markup you’re closing and re-opening the wrapping ul, which would break that .index()… if that was intentional, you’d have to store another kind of reference.

The Not Found for probably isn’t helping any either.

Augh… I’m sorry. I thought I had it fixed.

Mittineague May I ask where you are getting that error?>

m3g4p0p I will check out the sessions thing… Once I really do beat this thing into submission!!

And as for the opening and closing… That is baffling me… There are so many tags I don’t know which are needed and which are extra :frowning:

Thanks for the input


Vivaldi developer tools console pane

Ohhh… Mittineague
Thank you. Chrome has the same thing and I managed to dump the rogue stuff that was causing errors.

Now to fix the opening and closing of this menu…
m3g4p0p Could you maybe point me in the right direction please?

Thank you both very much :slight_smile:


There was just a </ul><ul> in your markup which divided the menu into 2 lists… but I just noticed you actually fixed it in your updated page anyway. ^^

Thank you very much… :slight_smile:

Much appreciated.
I will resume this later… I need to join the land of the living for a while :smile:


Hi again m3g4p0p
Can you help me out with this please…
I’ve done a little reading on session storage… but it is a bit beyond me…

Thanks :smiley:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.