I have been working on a website with around 20 pages that all have a side navigation bar. To make it easier to manage, I decided to centralize the links in a JavaScript (JS) file and include it on each HTML page. This way, any changes can be made quickly and uniformly across all pages.
One issue I'm facing is how to highlight the active page on the side navigation bar. Below is the JS code I am using (W3CSS is utilized for styling):
document.write('<h4>Services:</h4>\
<div class="w3-bar-block w3-light-grey">\
<a href="/page/7/alternative-dispute-resolution" class="w3-bar-item w3-button">Alternative Dispute Resolution</a>\
<a href="/page/8/appellate-practice" class="w3-bar-item w3-button">Appellate Practice</a>\
// More links...
<a href="/page/27/workmens-compensation" class="w3-bar-item w3-button">Workmens Compensation</a>\
</div>')
HTML:
<div class="w3-display-container w3-content w3-white" id="home" style="min-width:100%;">
<div class="w3-content w3-white">
<div class="w3-row">
<div class="w3-twothird w3-margin-top" style="font-size: 18px; text-align: justify; padding-left: 5%; padding-right: 5%;">
<p>content</p>
</div>
<div class="w3-third w3-padding">
<script src="services.js"></script>
</div>
</div>
</div>
</div>