I am trying to highlight the navigation button (in the menu) based on the page being viewed. Here is what I still have:
var loca = String(document.location.href);
if (loca) {
if(loca.search(RegExp("((/[\w]*)\.php)")) != -1) {
activate(loca.match(RegExp("((/[\w]*)\.php)").split("/").join("")));
} else {
activate("home");
}
}
function activate(bName) {
$(".button[name=" + bName + "]").css({
"border-left": "1px solid white",
"border-right": "1px solid white"
});
}
I want this to happen:
- Get page URL
- Get a specific page file name, and if it is not found, then we are on the main page.
- Using jQuery, I try to find the name of the button, and if the name matches the file name, highlight it.
The thing is, it only emphasizes the Home button. What am I doing wrong? Also, if you have any suggestions on how I can do this, let me know!
source
share