Kevin Powell - CommunityKP-C
Kevin Powell - Community4y ago
28 replies
Myndi

Auto-close similar childs

I have this code.
document.querySelectorAll('.button-collapse').forEach(button => {
  button.addEventListener("click", () => {
    const collapseBox = button.nextElementSibling;
    
    button.classList.toggle('active-btn');
    collapseBox.classList.toggle('active');
  });
});


Basically a collapsible box.

I wanted to make it so, whenever a different one gets opened, collapses the last one, but haven't been able to wrap my head around it. Tried some if statements, but can't quite find the logic.

Is there a way to make that?

If anyone is curious, it's right here: https://cozynova.online/windcutter/#New-Player
Comprehensive, concise and dynamic Ragnarok Online guide.
Wind Cutter Guide
Was this page helpful?