I have a static HTML web site. I want to store the the nav (top) menu in an external file so when I change the menu, I want to see the change in all pages.
I RE
menu.html
index.html
js file:
$(function() {
$("#nav").load("menu.html");
function activeNav() {
var pgurl = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
$("#nav ul li a").each(function(){
if($(this).attr("href") == pgurl || $(this).attr("href") == '' )
$(this).addClass("active");
});
}
setTimeout(function() {
activeNav();
}, 100);
});
The setTimeout lets the page load and then runs the function to see what link is active and then you can add a class in the css:
#nav ul li a.active {
color: #ff0000;
font-weight: bold;
}