.closest() should return a unique set of elements, not duplicates of the same ancestor. Fixes #6700
This commit is contained in:
parent
6a0942c9d5
commit
a2bd8a53f3
2 changed files with 14 additions and 6 deletions
|
@ -53,9 +53,10 @@ jQuery.fn.extend({
|
|||
},
|
||||
|
||||
closest: function( selectors, context ) {
|
||||
var ret;
|
||||
if ( jQuery.isArray( selectors ) ) {
|
||||
var ret = [], cur = this[0], match, matches = {}, selector, level = 1;
|
||||
|
||||
var cur = this[0], match, matches = {}, selector, level = 1;
|
||||
ret = [];
|
||||
if ( cur && selectors.length ) {
|
||||
for ( var i = 0, l = selectors.length; i < l; i++ ) {
|
||||
selector = selectors[i];
|
||||
|
@ -80,13 +81,12 @@ jQuery.fn.extend({
|
|||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret.length > 1 ? jQuery.unique(ret) : ret;
|
||||
}
|
||||
|
||||
var pos = jQuery.expr.match.POS.test( selectors ) ?
|
||||
jQuery( selectors, context || this.context ) : null;
|
||||
|
||||
return this.map(function( i, cur ) {
|
||||
ret = jQuery.map(this.get(),function( cur,i ) {
|
||||
while ( cur && cur.ownerDocument && cur !== context ) {
|
||||
if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) {
|
||||
return cur;
|
||||
|
@ -95,6 +95,10 @@ jQuery.fn.extend({
|
|||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
ret = ret.length > 1 ? jQuery.unique(ret) : ret;
|
||||
|
||||
return this.pushStack( ret, "closest", selectors );
|
||||
},
|
||||
|
||||
// Determine the position of an element within
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue