I'm using a 10-item unordered list as a navigation bar. Using SSI, I put the header and navigation bar into every file. I'd like a way to add class="active"
to the ruleset of the currently active page (the current page's corresponding <li>
will have a different style).
Including the file in every page means that, in the included file, none of the items can have the active class.
Is there a way to do this in just a few lines of code? (using jQuery/JS)
My other option is to match the last part of the URL to part of the href
of the anchor within each list item.
Solution: (courtesy of RomanGorbatko)
var tab = window.location.pathname.split("/");
tab = tab[tab.length - 1]; // This probably is not efficient - suggestions?
if (tab != "") $("#nav a#" + tab).addClass("active");