I know its more than likely been asked before but I’ve searched all over the place trying to figure this out. I already have JS that will change the navbar li class to active on navbar click as shown below, that works fine. But I also have a “next” button that should also do the same thing on click, change the li class of the nav bar to active. The button is set to hide the current tab, and show the next tab so the users wont have to keep scrolling up to click the next tab. No matter what i’ve done i cant get this to work.
// Add active class to the current button (highlight it)
var header = document.getElementById("navsub");
var btns = header.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";
});
}
and Below is the associated html
<ul id="navsub" class="navsub">
<li class="nav-item active"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs1">Contact Info</a></li>
<li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs2">Case</a></li>
<li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs3">Processor</a></li>
<li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs4">Cooling</a></li>
<li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs5">RAM</a></li>
<li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs6">Storage</a></li>
<li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs7">Power Supply</a></li>
<li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs8">Fans, Lighting & Sleeving</a></li>
<li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs9">Accessories</a></li>
<li class="nav-item"><a style="cursor:pointer;" onclick="showStuff(this)" id="tabs10">Graphics Card</a></li>
</ul>
