Skip to content

Instantly share code, notes, and snippets.

@jjjjcccjjf
Last active August 31, 2018 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjjjcccjjf/23094356a0a4b721eb4255ed12da26e9 to your computer and use it in GitHub Desktop.
Save jjjjcccjjf/23094356a0a4b721eb4255ed12da26e9 to your computer and use it in GitHub Desktop.
// Put in head
// For adding class based on window hash
$(window).on('hashchange', function() {
let hash = window.location.hash;
$('a').removeClass('active');
$('a[href=\"' + hash + '\"]').addClass('active');
});
// ... in the body
// Example how to apply
// Just put the target in the href
<ul class="first">
<li><a href="#trigger11">Home</a></li>
<li><a href="#trigger14">Infrastructure</a></li>
// ...
// Make the href
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment