I recently implemented an accordion feature on my website located at . You'll notice that there are two accordion fields named "DONE-FOR-YOU WEBSITE" and "WEEKEND WEBSITE WARRIOR". When you click on these fields, their respective panels open up as intended. However, I've encountered an issue where the panels overlap each other when opened simultaneously.
My goal is to ensure that only one panel is open at a time to prevent this overlapping behavior. Despite trying various solutions in my JavaScript code below, I haven't been successful in achieving this functionality.
//Js file for accordian
var acc = document.getElementsByClassName("accordian-left");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight){
panel.style.maxHeight = null;
panel.style.zIndex = "0";
panel.style.border = "0";
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
jQuery(this).css('margin-bottom','10px');
panel.style.zIndex = "1";
panel.style.border = "3px solid #eee";
}
}
}