Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

220
Visualizações
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 Respostas
Responde à pergunta

0

can you do this:

d.className = "current";
Instead of:-
d.className += "current";
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda