X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftraversing.js;h=1342c59599e97c03e8b4a64ddda339636ace268c;hb=0790989eb60df9df884837c05f90bab14df0704e;hp=669c70a509a2809961aa754d03428633d51da7db;hpb=87869b8b81380617cfad8788799ee40de0e3e9c4;p=jquery.git diff --git a/src/traversing.js b/src/traversing.js index 669c70a..1342c59 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -51,13 +51,13 @@ jQuery.fn.extend({ return this.pushStack( jQuery.winnow(this, selector, true), "filter", selector ); }, - closest: function( selector ) { + closest: function( selector, context ) { var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null, closer = 0; return this.map(function(){ var cur = this; - while ( cur && cur.ownerDocument ) { + while ( cur && cur.ownerDocument && cur !== context ) { if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) { jQuery.data(cur, "closest", closer); return cur; @@ -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() { @@ -120,4 +130,4 @@ jQuery.each({ return this.pushStack( jQuery.unique( ret ), name, selector ); }; -}); \ No newline at end of file +});