How do I highlight active link in a menu
I know this should be easy but I just can't get it working. My site has a main topnav. It also has a submenu that jumps to various anchors in the body of the page.. In this example: the main menu opens the page "About Us". I set the "About Us' link active manually in that page. The submenu jumps to anchors in the body of the same page. They are "Who We Are", "Where We Are" and "The Journey". Because you can jump back and forth within the page, the active link has to be set with a script that highlights the choice you jumped to and unhighlights the other choices.

So far I have it so it will highlight the choice you jump to but it does not remove the highlight from the other choices. So they all end up highlighted.
<div class="subnav" id="mySubnav">
<a class="btn active" href="#whoweare">Who We Are</a>
<a class="btn" href="#where-we-are">Where We Are</a>
<a class="btn" href="#thejourney">The Journey</a>
</div>
<!-- -->
<script>
// Add active class to the current button (highlight it)
var header = document.getElementById("mySubnav");
var btns = header.getElementsByClassName("btn");
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function () {
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(
" active",
""
);
this.className += " active";
});
}
</script>"Who We Are" is active initially as that's where you land when opening the page. I think I'm missing only a small detail here but I can't find it.
Thanks,
Sean
