design/public/assets/js/tabs.js

32 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-11-08 00:15:57 +00:00
document.querySelectorAll('.tabsMain').forEach(tabsMain => {
2024-11-16 13:46:05 +00:00
const tabsTopElements = tabsMain.querySelectorAll('.tabsMainTopElement, .tabsMainTopElementAlt');
2024-11-08 00:15:57 +00:00
const tabsMidElements = tabsMain.querySelectorAll('.tabsMainMidElement');
tabsTopElements.forEach((tab, index) => {
tab.addEventListener('click', () => {
// Remove active class from all tabs and content
2024-11-16 13:46:05 +00:00
tabsTopElements.forEach(t => {
t.classList.remove('tabsMainTopElementActive');
t.classList.remove('tabsMainTopElementActiveAlt');
});
2024-11-08 00:15:57 +00:00
tabsMidElements.forEach(m => m.classList.remove('tabsMainMidElementActive'));
// Add active class to the clicked tab and corresponding content
tab.classList.add('tabsMainTopElementActive');
2024-11-16 13:46:05 +00:00
if (tab.classList.contains('tabsMainTopElementAlt')) {
tab.classList.add('tabsMainTopElementActiveAlt');
}
2024-11-08 00:15:57 +00:00
tabsMidElements[index].classList.add('tabsMainMidElementActive');
// Set active class on the parent tabsMain
tabsMain.classList.add('tabsMainActive');
// Remove active class from all other tabsMain
document.querySelectorAll('.tabsMain').forEach(otherTabsMain => {
if (otherTabsMain !== tabsMain) {
otherTabsMain.classList.remove('tabsMainActive');
}
});
});
});
});