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

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

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