Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
How do i make current nav link which is also home page active when it's the current page?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

can you do this:

d.className = "current";
Instead of:-
d.className += "current";
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!