full code is here : https://github.com/M-lakshan/toggle-menu-test.git
//common toggle part in the HTML(only the first div tag class "Qi" may differ...
//there are 5 of them(as Qi,Qii,Qiii,Qiv,Qv)
<main>
<!--***-->
<div class="Qi">
<div class="tab">
<a id="anchor" class="active">
How many team members can I invite?
<img id="clickingArrow" class="active" src="./icon-arrow-down.svg" alt="click-arrow">
</a>
<div id="dropdown" class="active">
<p class="text">
You can invite up to 2 additional users on the Free plan. There is no limit on
team members for the Premium plan.
</p>
</div>
</div>
</div>
<hr>
<!--***-->
</main>
//just JS
const arrowS = document.querySelectorAll("#clickingArrow");
arrowS.forEach(function(arrow) {
arrow.addEventListener( "click", function(titlePop) {
setTimeout ( () => {
//for dropdown
let text = document.getElementById("dropdown");
text.classList.toggle("active");
}, 500);
//for anchor
const container = titlePop.currentTarget.parentElement;
container.classList.toggle("active");
//for clickingArrow
this.classList.toggle("active");
});
});
This only works for the first toggle element in the HTML. full code(with HTML & CSS) is available in my provided Github link.