Skip to content

Instantly share code, notes, and snippets.

@the-architect
Created April 12, 2017 20:13
Show Gist options
  • Save the-architect/6b29f84657a7e91360f21ca250416f5c to your computer and use it in GitHub Desktop.
Save the-architect/6b29f84657a7e91360f21ca250416f5c to your computer and use it in GitHub Desktop.
ES6 Simple Tab Control
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