Created
April 12, 2017 20:13
-
-
Save the-architect/6b29f84657a7e91360f21ca250416f5c to your computer and use it in GitHub Desktop.
ES6 Simple Tab Control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class TabControl { | |
constructor(element){ | |
this.element = element; | |
this.element.addEventListener('click', this.handleClick.bind(this)); | |
let firstOption = this.element.querySelector('.tab-option'); | |
firstOption.classList.add('active'); | |
} | |
handleClick(e){ | |
if(e.srcElement.classList.contains('tab-option')){ | |
this.element.querySelectorAll('.tab-option').forEach((e) => { e.classList.remove('active') }); | |
e.srcElement.classList.add('active'); | |
} | |
} | |
} | |
document.querySelectorAll('.tab-control').forEach((element) => { | |
new TabControl(element); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment