How to store click event in a local storage to use it after page refresh.
const container = document.querySelector('.filter ul');
container.addEventListener('click',(event) =>{
const closest = event.target.closest('.accordion-header');
if (!closest) return;
closest.classList.add('active');
closest.nextElementSibling.classList.add('active');
});
<div class = "filter">
<ul>
<li>
<h4 class = ""> Accordion </h4>
<p> Hello,world </p>
</li>
</ul>
</div>
You can use the
localStorageAPI. You can save the state of the active class for each accordion header and its sibling in local storage, so that you can retrieve it after the page refreshes.