Last active
January 20, 2019 04:51
-
-
Save momin-riyadh/3ac37bd39db795ba6c177a31fec24a46 to your computer and use it in GitHub Desktop.
Vanilla JavaScript Active Class onDemand
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
<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