Skip to content

Instantly share code, notes, and snippets.

@muks999
Created June 14, 2018 00:48
Show Gist options
  • Save muks999/a62a72f7bc382c89b81ae5e03002f2b5 to your computer and use it in GitHub Desktop.
Save muks999/a62a72f7bc382c89b81ae5e03002f2b5 to your computer and use it in GitHub Desktop.
Tabs Native JS
(function () {
let tabNav = document.querySelectorAll('.tab-list>li'),
tabContent = document.querySelectorAll('.tab-content__item'),
tabName;
tabNav.forEach(function (item) {
item.addEventListener('click', selectTabNav)
});
function selectTabNav() {
tabNav.forEach(function (item) {
item.classList.remove( ); // Удаляем активный укласс у элемента списка
});
this.classList.add( ); // Добавляем активный укласс у элемента списка
tabName = this.getAttribute('data-tab');
selectTabContent(tabName);
}
function selectTabContent(tab) {
tabContent.forEach(function (item) {
if (item.classList.contains(tab)) {
item.classList.add('tab-content__item--active');
} else {
item.classList.remove('tab-content__item--active');
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment