Encountering a minor issue with the accordion/tab layout provided in this link:
https://jsfiddle.net/drj3m5tg/
The problem is that on mobile, the "+" icon remains as "-" when opening and closing tabs. Also, in desktop view, sometimes tabs need to be clicked twice to reveal the content below. Upon inspecting in Chrome, it appears that the active class is not removed until clicking again. Is there a solution using JS to address this behavior?
const accordion = document.getElementsByClassName("accordion");
const panel = document.getElementsByClassName("panel");
for(let i = 0; i < accordion.length; i++){
accordion[i].addEventListener('click', function(){
removeOpen();
// add active class to clicked element and open class to next sibling
const toggleResult = this.classList.toggle('active');
this.nextElementSibling.classList.toggle('panel-open', toggleResult);
});
};
// remove open class for all elements
function removeOpen (){
for(let i = 0; i < panel.length; i++) {
panel[i].classList.remove('panel-open');
}
};