Skip to content

Instantly share code, notes, and snippets.

@fredericAerts
Created January 19, 2016 18:37
Show Gist options
  • Save fredericAerts/66d51b7db8283f82dd75 to your computer and use it in GitHub Desktop.
Save fredericAerts/66d51b7db8283f82dd75 to your computer and use it in GitHub Desktop.
web developer in 3days - v7
window.document.addEventListener('DOMContentLoaded', function() {
var tabLinks = window.document.querySelectorAll('.tab-links-item');
var tabLinksArray = [].slice.call(tabLinks);
tabLinksArray.forEach(function(tabLink) {
tabLink.addEventListener('click', function(event) {
event.preventDefault();
if(!tabLink.classList.contains('active')) {
// update tab links
tabLink.parentNode.querySelector('.tab-links-item.active').classList.remove('active');
tabLink.classList.add('active');
// update tab panes
var targetPane = window.document.querySelector(tabLink.getAttribute('href'));
targetPane.parentNode.querySelector('.active').classList.remove('active');
targetPane.classList.add('active');
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment