Skip to content

Instantly share code, notes, and snippets.

@momin-riyadh
Last active January 20, 2019 04:51
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 momin-riyadh/3ac37bd39db795ba6c177a31fec24a46 to your computer and use it in GitHub Desktop.
Save momin-riyadh/3ac37bd39db795ba6c177a31fec24a46 to your computer and use it in GitHub Desktop.
Vanilla JavaScript Active Class onDemand
<div id="js-id-name" class="cm-category-nav">
<a class="anchor-link-class-name active-class" href="homepage-tags.html">Featured</a>
<a class="anchor-link-class-name" href="javascript:void(0)">Water</a>
<a class="anchor-link-class-name" href="javascript:void(0)">Travel</a>
<a class="anchor-link-class-name" href="javascript:void(0)">House</a>
<a class="anchor-link-class-name" href="javascript:void(0)">Old</a>
</div>
<script>
/**
* Personal Profile Active Links
* Active Class Added
* personal-profile.html
* _personal-profile.scss
*/
;(function () {
var followers = document.getElementById("js-id-name");
var activeLinks = followers.getElementsByClassName("anchor-link-class-name");
for (var i = 0; i < activeLinks.length; i++) {
activeLinks[i].addEventListener("click", function () {
var current = document.getElementsByClassName("active-class");
current[0].className = current[0].className.replace(" active-class", "");
this.className += " active-class";
})
}
})();
// End
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment