diff --git a/src/traversing.js b/src/traversing.js index 1633e2e1..cfb344b9 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -100,23 +100,24 @@ jQuery.fn.extend({ var pos = POS.test( selectors ) ? jQuery( selectors, context || this.context ) : null; - var ret = []; + var ret = []; - for ( var i=0,j=this.length; i -1 : jQuery.find.matches(selectors, [cur]).length ) { + while ( cur ) { + if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) { ret.push( cur ); - break; + break; + } else { - cur = cur.parentNode; - if ( !cur.ownerDocument || cur === context ) { - break; - } - } - } - } + cur = cur.parentNode; + if ( !cur.ownerDocument || cur === context ) { + break; + } + } + } + } ret = ret.length > 1 ? jQuery.unique(ret) : ret;