From: Martijn W. van der Lee Date: Mon, 11 Jan 2016 19:59:33 +0000 (+0100) Subject: Traversing: .not/.filter consistency with non-elements X-Git-Tag: 3.0.0-beta1~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0e2f8f9effd2c95647be534bf9055e099aad7cfd;p=jquery.git Traversing: .not/.filter consistency with non-elements Fixes gh-2808 Close gh-2809 --- diff --git a/src/traversing/findFilter.js b/src/traversing/findFilter.js index ee76a57a7..f3a929e53 100644 --- a/src/traversing/findFilter.js +++ b/src/traversing/findFilter.js @@ -33,7 +33,7 @@ function winnow( elements, qualifier, not ) { } return jQuery.grep( elements, function( elem ) { - return ( indexOf.call( qualifier, elem ) > -1 ) !== not; + return ( indexOf.call( qualifier, elem ) > -1 ) !== not && elem.nodeType === 1; } ); } diff --git a/test/unit/traversing.js b/test/unit/traversing.js index 7766fd3cb..d38d40be5 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -430,6 +430,17 @@ QUnit.test( "not(jQuery)", function( assert ) { assert.deepEqual( jQuery( "p" ).not( jQuery( "#ap, #sndp, .result" ) ).get(), q( "firstp", "en", "sap", "first" ), "not(jQuery)" ); } ); +QUnit.test( "not(Selector) excludes non-element nodes (gh-2808)", function( assert ) { + assert.expect( 3 ); + + var mixedContents = jQuery( "#nonnodes" ).contents(), + childElements = q( "nonnodesElement" ); + + assert.deepEqual( mixedContents.not( "*" ).get(), [], "not *" ); + assert.deepEqual( mixedContents.not( "[id=a],[id=b]" ).get(), childElements, "not [id=a],[id=b]" ); + assert.deepEqual( mixedContents.not( "[id=a],*,[id=b]" ).get(), [], "not [id=a],*,[id=b]" ); +} ); + QUnit.test( "has(Element)", function( assert ) { assert.expect( 3 ); var obj, detached, multipleParent;