Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda