diff options
author | Dave Methvin <dave.methvin@gmail.com> | 2016-08-02 16:41:34 -0400 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2016-08-10 10:04:24 -0400 |
commit | 560c0c6f995a4f7584dac5be8fe5eea114a95f69 (patch) | |
tree | 36db0299b2c8833075eca4f0915717aaea44ea54 /src | |
parent | cca2aa2254e805612d12bca457afefa920d0af5c (diff) | |
download | jquery-560c0c6f995a4f7584dac5be8fe5eea114a95f69.tar.gz jquery-560c0c6f995a4f7584dac5be8fe5eea114a95f69.zip |
Traversing: Let .not(arraylike) pass non-element nodes
Fixes gh-3226
Closes gh-3261
Diffstat (limited to 'src')
-rw-r--r-- | src/traversing/findFilter.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/traversing/findFilter.js b/src/traversing/findFilter.js index 92d6753b4..3bd036a18 100644 --- a/src/traversing/findFilter.js +++ b/src/traversing/findFilter.js @@ -15,24 +15,29 @@ function winnow( elements, qualifier, not ) { return jQuery.grep( elements, function( elem, i ) { return !!qualifier.call( elem, i, elem ) !== not; } ); - } + // Single element if ( qualifier.nodeType ) { return jQuery.grep( elements, function( elem ) { return ( elem === qualifier ) !== not; } ); - } - if ( typeof qualifier === "string" ) { - if ( risSimple.test( qualifier ) ) { - return jQuery.filter( qualifier, elements, not ); - } + // Arraylike of elements (jQuery, arguments, Array) + if ( typeof qualifier !== "string" ) { + return jQuery.grep( elements, function( elem ) { + return ( indexOf.call( qualifier, elem ) > -1 ) !== not; + } ); + } - qualifier = jQuery.filter( qualifier, elements ); + // Simple selector that can be filtered directly, removing non-Elements + if ( risSimple.test( qualifier ) ) { + return jQuery.filter( qualifier, elements, not ); } + // Complex selector, compare the two sets, removing non-Elements + qualifier = jQuery.filter( qualifier, elements ); return jQuery.grep( elements, function( elem ) { return ( indexOf.call( qualifier, elem ) > -1 ) !== not && elem.nodeType === 1; } ); |