Skip to content

Instantly share code, notes, and snippets.

@tuor4eg
Last active August 22, 2018 12:18
Show Gist options
  • Save tuor4eg/5b3f6dd778637348c24ac074eff3165f to your computer and use it in GitHub Desktop.
Save tuor4eg/5b3f6dd778637348c24ac074eff3165f to your computer and use it in GitHub Desktop.
export default () => {
// BEGIN (write your solution here)
const makeActive = (element) => {
const link = element.getAttribute('href').substr(1);
const currentTab = element.parentNode.parentNode.getElementsByClassName('nav-link active')[0];
const currentLink = currentTab.getAttribute('href').substr(1);
const currentDiv = document.getElementById(link);
const findDiv = document.getElementById(link);
currentDiv.setAttribute('class', 'tab-pane');
findDiv.setAttribute('class', 'tab-pane active');
element.setAttribute('class', 'nav-link active');
currentTab.setAttribute('class', 'nav-link');
return;
};
const nav = document.querySelectorAll('a[data-toggle]');
nav.forEach(node => {
node.addEventListener('click', makeActive(node));
});
// END
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment