Skip to content

Commit 733f55f

Browse files
committed
Selector: Fix querying on document fragments
1 parent 5167381 commit 733f55f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/selector-native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ jQuery.extend( {
5151
return results;
5252
}
5353

54-
// Early return if context is not an element or document
55-
if ( ( nodeType = context.nodeType ) !== 1 && nodeType !== 9 ) {
54+
// Early return if context is not an element, document or document fragment
55+
if ( ( nodeType = context.nodeType ) !== 1 && nodeType !== 9 && nodeType !== 11 ) {
5656
return [];
5757
}
5858

test/unit/selector.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,21 @@ QUnit.testUnlessIE( "jQuery.contains within <template/> doesn't throw (gh-5147)"
19081908
assert.ok( true, "Didn't throw" );
19091909
} );
19101910

1911+
QUnit.test( "find in document fragments", function( assert ) {
1912+
assert.expect( 1 );
1913+
1914+
var elem,
1915+
nonnodes = jQuery( "#nonnodes" ).contents(),
1916+
fragment = document.createDocumentFragment();
1917+
1918+
nonnodes.each( function() {
1919+
fragment.appendChild( this );
1920+
} );
1921+
1922+
elem = jQuery( fragment ).find( "#nonnodesElement" );
1923+
assert.strictEqual( elem.length, 1, "Selection works" );
1924+
} );
1925+
19111926
QUnit.test( "jQuery.uniqueSort", function( assert ) {
19121927
assert.expect( 14 );
19131928

0 commit comments

Comments
 (0)