0

I have a side nav with sections that are accordions. I want to save the state of the accordion whether it be display = none or block.

function toggle(tgl){
btn = document.getElementById(tgl.id+'1');
expiration = new Date();
expiration.setFullYear(expiration.getFullYear()+1);
btn.classList.toggle("active");
    if (tgl.style.display == 'none' || tgl.style.display == '' ) {
        tgl.style.display = 'block';
        var show = 'tgl.style.display = "block"';

        document.cookie = show; 
        console.log(bong + '  hyar');
    } else {
        tgl.style.display = 'none';
        var hide = 'tgl.style.display = "none"'
        document.cookie = hide;'expires = '+expiration.toUTCString();
        console.log(document.cookie);
    }
}
Rene Limon
  • 614
  • 4
  • 16
  • 34
Griehle
  • 114
  • 1
  • 10
  • 1
    Follow url hash method to keep track of the states of nav accordion. For example, assign id to each nav accordion tab and when you click them, their ids will be passed to the url as hash like `#accordion-tab-1` and conditionally check the hash in the url and set the state of the accordion tab accordingly every time you reload the page. This requires some conditional stuff and hope I've given you some idea over this. Hope you got it and get to work at it. – Wolverine Dec 09 '16 at 23:06
  • Thank you for that idea. I use a few GET methods in order for the pages to work, and i am looking more specifically at ways to run only the nav which is an include to the rest of all the other pages. – Griehle Dec 09 '16 at 23:41
  • I've got no other idea in this case except there is an other idea popped up which is by using cookie with JavaScript. Store accordion tab states in cookies. – Wolverine Dec 09 '16 at 23:43
  • exactly what this is an attempt at. – Griehle Dec 12 '16 at 17:04
  • You can use cookies to save the state of accordion tabs. – Wolverine Dec 12 '16 at 18:27
  • can you show your work? :) – Griehle Dec 12 '16 at 18:55
  • http://stackoverflow.com/questions/4825683/how-do-i-create-and-read-a-value-from-cookie – Griehle Dec 13 '16 at 20:40

0 Answers0