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

164
Views
Cambio de color de la pestaña activa de la barra de navegación

Mi código no funciona, no sé por qué.

Alguien por favor ayúdeme.

No puedo agregar un nombre de clase a la barra de navegación activa

 <nav class="navbar"> <ul> <li class="nav-list"><a href="home.html" class="navlink">Home</a></li> <li class="nav-list"><a href="aboutme.html" class="navlink">About me</a></li> <li class="nav-list"><a href="work.html" class="navlink">Work</a></li> <li class="nav-list"><a href="contact.html" class="navlink">Contact me</a></li> </ul> </nav>

CSS

 .nav-list a.active{ color:rgb(28, 162, 224); }

JavaScript

 const currentlocation = location.href; const menuitem = document.querySelectorAll('nav-list a'); const menulenght = menuitem.length; for(let i = 0; i < menulenght; i++){ if(menuitem[i].href === currentlocation){ menuitem[i].className = 'active'; } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

1) Tienes que usar . para selector de clase como:

 document.querySelectorAll( '.nav-list a' );

2) Tienes que usar el método add para agregar una nueva clase como:

 menuitem[i].classList.add( "active" )

JS

 const currentlocation = location.href; const menuitem = document.querySelectorAll( '.nav-list a' ); for ( let i = 0; i < menuitem.length; i++ ) { if ( menuitem[i].href === currentlocation ) { menuitem[i].classList.add( "active" ) } }

Además, hay un error tipográfico en su código actual: lenght en lugar de length

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!