Core: Implement .even() & .odd() to replace POS :even & :odd

`:even` & `:odd` are deprecated since jQuery 3.4.0 & will be removed in 4.0.0.
The new `even()` & `odd()` methods will make the migration easier.

Closes gh-4485

(cherry picked from commit 78420d427c)
This commit is contained in:
Michał Gołębiowski-Owczarek
2019-09-24 02:04:53 +02:00
committed by Michał Gołębiowski-Owczarek
parent 0c67da4b74
commit 409cbda7fe
2 changed files with 24 additions and 0 deletions

View File

@@ -105,6 +105,18 @@ jQuery.fn = jQuery.prototype = {
return this.eq( -1 );
},
even: function() {
return this.pushStack( jQuery.grep( this, function( _elem, i ) {
return ( i + 1 ) % 2;
} ) );
},
odd: function() {
return this.pushStack( jQuery.grep( this, function( _elem, i ) {
return i % 2;
} ) );
},
eq: function( i ) {
var len = this.length,
j = +i + ( i < 0 ? len : 0 );