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

206
Views
¿Cómo elimino la clase del botón de la barra de navegación cuando se selecciona un nuevo enlace [Javascript]?

Estoy tratando de hacer un estado activo en mi enlace cuando se hace clic, que permanece hasta que se hace clic en otro enlace. Me gustaría que la clase se elimine y se transfiera al siguiente enlace cuando se haga clic.

Actualmente se puede activar y desactivar en cada enlace.

 // navbar toggle for active state document.getElementById('navbar__list').addEventListener("click", function(event){ event.target.classList.toggle('funcElemStyle'); });
 .funcElemStyle { background: #333; }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

En lugar de usar javascript para lograr esta funcionalidad, puede usar CSS para lograr el mismo efecto usando :active .

por ejemplo:

 /* Selects the link element. */ a:active { color: #4444AA; }

también puede usar :hover si desea efectos cuando se desplaza. CSS también permite el encadenamiento, por lo que si desea que se aplique un efecto cuando se desplaza sobre él y está activo, puede usar :active:hover

about 4 years ago · Juan Pablo Isaza Report

0

En lugar de alternar, use .add() y . remove() funciones. Ejecute snippet para ver un ejemplo.

 document.querySelector("div").addEventListener("click", event=>{ event.target.classList.remove("red") })
 div{ width: 100px; height: 100px; background: green; } .red{ background: red; }
 <div class="red"></div>

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!