Dropdown menu remain open after click and refresh

Viewed 86

I have a problem on how to make my dropdown remain open after clicking and avoid closing after refresh.

Here's what I've done.

<button class="dropdown_btn">
   <span>Sample</span>
</button>
<div class="dropdown-container">
   <a href="sample.php">Sample 1</a>
   <a href="sample.php">Sample 2</a>
</div>
<br>
<button class="dropdown_btn">
  <span>Sample</span>
</button>
<div class="dropdown-container">
   <a href="sample.php">Sample 1</a>
   <a href="sample.php">Sample 2</a>
</div>

Jsfiddle Link: https://jsfiddle.net/Mandy201/7w8t2muc/

1 Answers

You can use the localStorage with a simply flag. On open the flag become true, on close the flag become false. For the refresh you need to test your var contains in localStorage. If is true, display the menu, if is false do not display the menu

Related