class Tabs { constructor(selector) { this.tab = document.querySelector(selector) this.items = this.tab.querySelectorAll('li') this.change() } change() { this.tab.addEventListener('click', (e) => { if (e.target.tagName == 'LI') { let _this = e.target this.items.forEach(item => { item.classList.remove('active') }) _this.classList.add('active') } }) } }
new Tabs('#open') new Tabs('#close')