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

201
Vistas
How do I remove the class from the navbar button when a new link is selected [Javascript]

I am trying to make an active state on my link when clicked, which remains until another link is clicked. I'd like to have the class removed and transferred to the next link when clicked.

Currently it can be toggled on and off on each link.

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

0

Instead of using javascript to achive this functionality, you can use CSS to achieve the same effect by using :active.

for example:

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

you can also use :hover if you want effects when hovered. CSS also allows chaining so if you want an effect to apply when it is hovered over and active, you can use :active:hover

about 4 years ago · Juan Pablo Isaza Denunciar

0

Instead of toggle use .add() and .remove() functions. Run snippet for an example.

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 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