document.querySelectorAll('.bt-product-category-card5__icon-wrapper').forEach(iconWrapper => {
iconWrapper.addEventListener('click', function () {
const parentCard = this.closest('.bt-product-category-card5');
const subElement = parentCard.querySelector('.bt-product-category-card5__sub');
// Toggle the active class on the parent element
parentCard.classList.toggle('active');
// If the parent has the active class, show the sub-element
if (parentCard.classList.contains('active')) {
subElement.style.display = 'flex';
// To animate the height, first, we need to get its actual height and then set it
const subHeight = subElement.scrollHeight; // Get full height of the element
subElement.style.height = `${subHeight}px`; // Set height to the actual height
} else {
// If the active class is removed, reverse the changes
subElement.style.height = '0'; // Collapse the element by setting height to 0
setTimeout(() => {
subElement.style.display = 'none'; // Set display:none after animation
}, 400); // Match the timing of the transition (0.4s in CSS)
}
});
});