Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
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 Respuestas
Responde la pregunta

0

can you do this:

d.className = "current";
Instead of:-
d.className += "current";
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda