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

153
Visualizações
Migrating :odd selector behaviour after jQuery Depreciation

I am having issues migrating the last bit of our code to exit depreciation. We use jQuery 3.6, and since jQuery 3.4 the :odd selector is depreciated.

As of jQuery 3.4, the :odd pseudo-class is deprecated. Remove it from your selectors and filter the results later using .odd() (available in jQuery 3.5.0 or newer).

However, it appears to be very difficult to retain the background color for every 3rd row.

.divGrey {
  background-color: #c0c0c0;
}
$('.container').filter(function () {
  return $(this).children().length === 3;
}).filter(':odd').addClass('divGrey'); // :odd Depreciated

I can do .odd().addClass('divGrey') but I lose the background I want to retain for every third child. How can I do this? Do I need to remove filter function?

Any help appreciated - thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To do what you require you can use the index argument provided to a function handler in filter() and return a boolean value to state if the element's index is even or odd, like this:

$('.container').filter(i => i % 2).addClass('divGrey');
.divGrey {
  background-color: #c0c0c0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="container">0</div>
<div class="container">1</div>
<div class="container">2</div>
<div class="container">3</div>
<div class="container">4</div>
<div class="container">5</div>

Note that I removed the first filter() call as it wasn't relevant to the question.

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