So i had the working solution untill i decided to change my home page(because it was just an empty page) to one of my nav links. Now when i click on the navlink it redirects me to the home page which has no url, thus the link can't be found. This is the code that i used before:
var activePage = window.location.pathname;
const navLinks = document.querySelectorAll("nav a").
forEach(link => {
if (link.href.includes(activePage)) {
link.classList.add("current");
} });
This is what i tried
var activePage = window.location.pathname;
if (activePage == "/") {
activePage="/ProjectsList"
}
var d = document.getElementById("navLink3");
/*d.className += "current";*/
const navLinks = document.querySelectorAll("nav a").
forEach(link => {
if (activePage == "/AdminPage" || activePage == "/Account/UserProfile") {
if (link.href.includes(activePage)) {
link.classList.add("current");
}
}
else {
d.className += "current";
console.log("wok")}
});
it technically reaches the else statement but the class doesn't get applied.
I want to mention that i use asp.net and i changed the index page by writing in the .cshtml of the nav page @page "/"
Any help?
can you do this:
d.className = "current";
Instead of:-
d.className += "current";