50projects50days/mobile-tab-navigation/script.js
2020-10-19 13:31:38 -04:00

21 lines
522 B
JavaScript

const contents = document.querySelectorAll('.content')
const listItems = document.querySelectorAll('nav ul li')
listItems.forEach((item, idx) => {
item.addEventListener('click', () => {
hideAllContents()
hideAllItems()
item.classList.add('active')
contents[idx].classList.add('show')
})
})
function hideAllContents() {
contents.forEach(content => content.classList.remove('show'))
}
function hideAllItems() {
listItems.forEach(item => item.classList.remove('active'))
}