Created
February 28, 2019 04:13
-
-
Save wamoyo/44343affde89dd639890cc85ecff8de7 to your computer and use it in GitHub Desktop.
This file contains 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
// 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