Skip to content

Commit 0e2f8f9

Browse files
vanderleetimmywil
authored andcommittedJan 13, 2016
Traversing: .not/.filter consistency with non-elements
Fixes gh-2808 Close gh-2809
1 parent b0b280c commit 0e2f8f9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
 

‎src/traversing/findFilter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function winnow( elements, qualifier, not ) {
3333
}
3434

3535
return jQuery.grep( elements, function( elem ) {
36-
return ( indexOf.call( qualifier, elem ) > -1 ) !== not;
36+
return ( indexOf.call( qualifier, elem ) > -1 ) !== not && elem.nodeType === 1;
3737
} );
3838
}
3939

‎test/unit/traversing.js

+11
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,17 @@ QUnit.test( "not(jQuery)", function( assert ) {
430430
assert.deepEqual( jQuery( "p" ).not( jQuery( "#ap, #sndp, .result" ) ).get(), q( "firstp", "en", "sap", "first" ), "not(jQuery)" );
431431
} );
432432

433+
QUnit.test( "not(Selector) excludes non-element nodes (gh-2808)", function( assert ) {
434+
assert.expect( 3 );
435+
436+
var mixedContents = jQuery( "#nonnodes" ).contents(),
437+
childElements = q( "nonnodesElement" );
438+
439+
assert.deepEqual( mixedContents.not( "*" ).get(), [], "not *" );
440+
assert.deepEqual( mixedContents.not( "[id=a],[id=b]" ).get(), childElements, "not [id=a],[id=b]" );
441+
assert.deepEqual( mixedContents.not( "[id=a],*,[id=b]" ).get(), [], "not [id=a],*,[id=b]" );
442+
} );
443+
433444
QUnit.test( "has(Element)", function( assert ) {
434445
assert.expect( 3 );
435446
var obj, detached, multipleParent;

0 commit comments

Comments
 (0)