From 9de120e6d7cfffa3d990a6ccf23db3cd74e2bdc0 Mon Sep 17 00:00:00 2001 From: John Resig Date: Wed, 9 Sep 2009 00:21:21 +0000 Subject: Added support for .eq(-N), .first(), and .last(). Fixes #2164 and #4188. --- src/traversing.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/traversing.js b/src/traversing.js index f46820f84..1342c5959 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -78,7 +78,17 @@ jQuery.fn.extend({ }, eq: function( i ) { - return this.slice( i, +i + 1 ); + return i === -1 ? + this.slice( i ) : + this.slice( i, +i + 1 ); + }, + + first: function() { + return this.eq( 0 ); + }, + + last: function() { + return this.eq( -1 ); }, slice: function() { -- cgit v1.2.3