Skip to content

Instantly share code, notes, and snippets.

@wamoyo
Created February 28, 2019 04:13
Show Gist options
  • Save wamoyo/44343affde89dd639890cc85ecff8de7 to your computer and use it in GitHub Desktop.
Save wamoyo/44343affde89dd639890cc85ecff8de7 to your computer and use it in GitHub Desktop.
// on hashchange
window.addEventListener('hashchange', function (event) {
// grab the hash
var hash = location.hash.split('#')[1]
// grab the links with selectable class
var links = document.querySelectorAll('a.selectable')
// loop through the links
for (var i = 0; i < links.length; i++) {
// if the hash matches the href of the link
var href = links[i].href.split('#')[1]
if (hash === href) {
// change the style
links[i].classList.add()
} else {
links[i].classList.remove()
}
}
}, false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment