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

265
Vistas
How to change the class of a <li> element after clicking on a tab

I would like to modify the class of certain elements of my sidebar when some user clicks on a tab. In short, change the class of the sidebar elements to current class + " active"

I have implemented a partially working solution as I could after doing some research on my own.

This part of the code is key:

$(".setActive").click(function() {
            $(".sidebar-item:contains('"+$(this).attr("data-target")+"')").parent().parent().addClass(' active');
})

Actually, with that line of code, I change the class to active but there is a problem:

  • I don't know how to remove the active class from the previously visited sidebar elements, then I am getting something like this:

current result

How can I solve this issue?

JS FIDDLE LIVE DEMO

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Remove all active class added before adding the current one

$(".setActive").click(function() {
    $(".sidebar-element.active").removeClass('active');
    $(".sidebar-item:contains('"+$(this).attr("data-target")+"')").parent().parent().addClass(' active');
})
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