I have encountered an issue with using the "active" class on my navbar navigation items in Bootstrap 4. When I click on the links, the active state does not switch as intended. I have tried incorporating JavaScript solutions from similar questions but have been unsuccessful. It's important to note that these links are all on the same page and I want the user to easily identify which section they are currently viewing.
Below is my current JavaScript code:
$(".nav .nav-link").on("click", function(){
$(".nav").find(".active").removeClass("active");
$(this).addClass("active");
});
Here is a snippet of my HTML code for the navbar:
<header>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<img class="logo" src="images/logo.png" width="55px" align="left">
<a class="navbar-brand" href="index.html">ROWAN AEΠ</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<!--Div for Alignment Purposes Below -->
<div class="navig-align">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link active" href="#HOME">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#ABOUT">ABOUT</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">BOARD</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">RECRUITMENT</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">FAQ</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">CONTACT</a>
</li>
<li class="nav-item">
<a id="donatebutton" class="nav-link" href="http://www.example.org" target="_blank">DONATE
<img class="donateimg" src="images/externallink.png" alt=""></a>
</li>
</ul>
</div>
</div>
</nav>
</header>
If anyone can provide insight into how to adjust my script based on the HTML structure provided, I would greatly appreciate it.