How to keep the Accordion Menu open after clicking on the link and paging?

Asked

Viewed 171 times

1

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

For example:

By clicking on Link 3

directs to pg3 with Section 1 open

adaptation of w3schools

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

if($Cod == $codin) {puts the link in Bold-red}

Maybe if you include if in js, you can solve it (I don’t know how to do it)

HELPING

I have several menus with more than 200 links and this accordion menu feature is key to facilitate navigation

You can tell me an accordion menu

  • that keeps the Section open (if possible, mark the chosen link)

  • and opens a section and closes another

I really appreciate 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>

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.