I dont use Jquery and dont want to , I wanted to toggle a class again once next item is toggled with same class. so the class from previous one is removed. and only one class is toggled on at a time.
I tried adding document.getElementsByClassName(".panel").removeClass("open");
to the function to first remove all toggled class('open')
but that doesnt work.
i tried adding an id and trying to remove a class from that id still doesn't work
function toggleOpen() {
document.getElementsByClassName(".panel").removeClass("open");//this give me error
this.classList.toggle('open');
}
function toggleActive(e) {
if (e.propertyName.includes('flex')) {
this.classList.toggle('open-active');
}
}
const panels = document.querySelectorAll('.panel');
panels.forEach(panel => panel.addEventListener('click', toggleOpen));
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
Result
Uncaught TypeError: document.getElementsByClassName(...).removeClass is not a function