I have a script that creates an active CSS on link, but I think there are a lot of if statements. Can someone help me refactor this?
var link = window.location.pathname;
var currentPageName = window.location.href.match(/[^\/]+$/)[0];
var hl = $('#ih').val();
if (hl == 'True') {
var currentPageName = 'WVD';
}
if (window.location.href.indexOf("R") > -1) {
var currentPageName = window.location.href.match(/[^\/]+$/)[0];
}
if (window.location.href.indexOf("C") > -1) {
var currentPageName = window.location.href.match(/[^\/]+$/)[0];
}
if (location.pathname == "/") {
var currentPageName = 'MD';
}
$(".main-navigation ul li a").each(function () {
var link = $(this).attr("href");
if (link.indexOf(currentPageName) > -1) {
$(this).addClass("active");
$(this).css("color", "white");
$(this).css("text-decoration", "bold");
}
});
activebased on the url isn't this long. \$\endgroup\$