How to stop menu resetting when switching pages?

Hi…
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:
http://welshdragon.co/test/

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

Thanks for any help :slight_smile:

Tracy

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.

Tracy

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') {
  items.eq(current).find('ul').show()
}

items.click(function() {
  subs.hide()
  $('ul', this).show()
  sessionStorage.current = $(this).index()
})

fiddle

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 http://welshdragon.co/test/css/css/dash.css 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

Tracy

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:

Tracy

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:

Tracy

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:
Tracy

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