-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (30 loc) · 880 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const tabItems = document.querySelectorAll('.tab-item');
const tabContentItems = document.querySelectorAll('.tab-content-item');
// Select tab content item
function selectItem(e) {
// Remove all show and border classes
removeBorder();
removeShow();
// Add border to current tab item
this.classList.add('tab-border');
// Grab content item from DOM
const tabContentItem = document.querySelector(`#${this.id}-content`);
// Add show class
tabContentItem.classList.add('show');
}
// Remove bottom borders from all tab items
function removeBorder() {
tabItems.forEach(item => {
item.classList.remove('tab-border');
});
}
// Remove show class from all content items
function removeShow() {
tabContentItems.forEach(item => {
item.classList.remove('show');
});
}
// Listen for tab item click
tabItems.forEach(item => {
item.addEventListener('click', selectItem);
});