I have a navbar with following settings:-
<li class="nav-item active">
<a class="btn btn-outline-primary" href="/Index">Home<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="btn btn-outline-primary" href="/Root/About">About</a>
</li>
<li class="nav-item">
<a class="btn btn-outline-primary" href="/Root/Contact">Contact</a>
</li>
<li class="nav-item">
<a class="btn btn-outline-primary" href="/Search/LatestChanges">@Localizer["menu_LatestChanges"]</a>
</li>
javascript file, which helps to add and to remove active class
<script>
var btns = document.getElementsByClassName("nav-item");
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>
It does add the active class on button click, however, a strange thing is when you click on nav-item, it basically adds the active class and then remove/reset it back immediately to the original state, therefore, my Index remains active forever. I think we might need to change javascript logic. Your help is highly appreciated. Thanks