I found a helpful example on how to change link colors for the current page here.
Here is the script I added:
<script>
// current page highlight
$(document).ready(function() {
$("[href]").each(function() {
if (this.href == window.location.href) {
$(this).addClass("active");
}
});
});
</script>
I inserted this script into the <head>
section of these files: index.html
(the home page), about.html
, and store.html
For our website. Service links should not be highlighted, and Blog and My Account are currently inactive.
I then defined the corresponding style in my CSS:
.active {
color:#337ab7;
}
So when we're on the Home page (index.html), the Home link should display in color #337ab7
, similarly for About and Store pages.
However, I am still not seeing any changes. Do I need to modify anything in the JavaScript, CSS, or HTML to make it work properly?
Below is the HTML code for the Navigation Menu in question:
UPDATE: Applied active
class to the relevant links:
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div>
<a class="navbar-brand" href="http://nowordpress.gatewaywebdesign.com/">
<img src="assets/images/gatewaylogo.png">
</a>
</div>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="http://nowordpress.gatewaywebdesign.com/index.html" class="active">Home <span
class="sr-only">(current)</span></a></li>
<li><a href="http://nowordpress.gatewaywebdesign.com/about.html" class="active">About</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">
Services
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="http://nowordpress.gatewaywebdesign.com/website-design.html">Website Design</a></li>
<li><a href="http://nowordpress.gatewaywebdesign.com/graphic-design.html">Graphic Design</a></li>
<li><a href="http://nowordpress.gatewaywebdesign.com/promotional-products.html">Promotional Products</a></li>
<li><a href="http://nowordpress.gatewaywebdesign.com/search-engine-marketing.html">Search Engine Marketing</a></li>
<li><a href="http://nowordpress.gatewaywebdesign.com/wordpress-conversion.html">WordPress Conversion</a></li>
</ul>
</li>
<li><a href="/store.html" class="active">Store</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">My Account</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Once again, here is the live site. Appreciate your assistance.