aboutsummaryrefslogtreecommitdiffstats
path: root/src/core.js
diff options
context:
space:
mode:
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>2019-09-24 02:04:53 +0200
committerGitHub <noreply@github.com>2019-09-24 02:04:53 +0200
commit78420d427cf3734d9264405fcbe08b76be182a95 (patch)
tree83a4cc9b453f84228d9e1fe9015aa39e482c4b37 /src/core.js
parentf810080e8e92278bb5288cba7cc0169481471780 (diff)
downloadjquery-78420d427cf3734d9264405fcbe08b76be182a95.tar.gz
jquery-78420d427cf3734d9264405fcbe08b76be182a95.zip
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
Diffstat (limited to 'src/core.js')
-rw-r--r--src/core.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/core.js b/src/core.js
index 01f501d21..6dbc69eb0 100644
--- a/src/core.js
+++ b/src/core.js
@@ -100,6 +100,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 );