How do I keep the Accordion Menu open after clicking the link and paging?

1

I need the clicked link panel to remain open on the new page

For example:

Clicking on Link 3

route to pg3 with Section 1 open

w3schools adaptation

Note: the clicked link is marked on the new page using:

if ($ cod == $ codin) {places the link in bold-red}

Maybe if it includes if in js, it can solve (do not know how to do)

HELP

I have several menus with more than 200 links and this acordeon menu feature is essential for easy navigation

You can give me an accordion menu

  • Keep Section open (if possible, select the link you selected)

  • and opens a Section and closes another

Thanks a lot for the help

var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");

var panel = this.nextElementSibling;
if (panel.style.maxHeight){
   panel.style.maxHeight = null;
}
else {
  panel.style.maxHeight = panel.scrollHeight + "px";
}});}
<button class="accordion">Section 1</button>
<div class="panel">
  <li><a href="pg1">Link 1</a></li>
  <li><a href="pg2">Link 2</a></li>
  <li><a href="pg3">Link 3</a></li>
  <li><a href="pg4">Link 4</a></li>
</div>
<button class="accordion">Section 2</button>
<div class="panel">
  <li><a href="pg5">Link 6</a></li>
  <li><a href="pg6">Link 7</a></li>
</div>
    
asked by anonymous 07.12.2018 / 09:13

0 answers