Is there a way to prevent previously opened accordions from remaining open when opening another accordion? Any help on fixing this issue would be greatly appreciated. Thank you!
let acc = document.getElementsByClassName('ac-btn');
let i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function() {
this.classList.toggle('active-accardacon');
this.classList.toggle('active-ac');
this.nextElementSibling.classList.toggle('show');
}
}
<div class="accardacons">
<h2>Explanation of Steps</h2>
<div class="ac">
<button class='ac-btn'>How do our projects work?</button>
<div class="read-more-ac">
<p>Lorem ipsum dummy text...</p>
</div>
</div>
<div class="ac">
<button class='ac-btn'>More details about the steps</button>
<div class="read-more-ac">
<p>Lorem ipsum dummy text...</p>
</div>
</div>
<div class="ac">
<button class='ac-btn'>Can you really trust us?</button>
<div class="read-more-ac">
<p>Lorem ipsum dummy text...</p>
</div>
</div>
<div class="ac">
<button class='ac-btn'>What guarantees do you have for your work?</button>
<div class="read-more-ac">
<p>Lorem ipsum dummy text...</p>
</div>
</div>
</div>