Skip to content

Commit a619cb3

Browse files
gibson042dmethvin
authored andcommitted
Fix #11370: .siblings() shouldn't throw exception on a detached element
1 parent 7226cf2 commit a619cb3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/traversing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ jQuery.each({
204204
return jQuery.dir( elem, "previousSibling", until );
205205
},
206206
siblings: function( elem ) {
207-
return jQuery.sibling( elem.parentNode.firstChild, elem );
207+
return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
208208
},
209209
children: function( elem ) {
210210
return jQuery.sibling( elem.firstChild );

test/unit/traversing.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,15 @@ test("andSelf()", function() {
414414
});
415415

416416
test("siblings([String])", function() {
417-
expect(6);
417+
expect(7);
418418
deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
419419
deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
420420
deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
421421
deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
422422
var set = q("sndp", "en", "sap");
423423
deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
424424
deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" );
425+
equal( jQuery("<a/>").siblings().length, 0, "Detached elements have no siblings (#11370)" );
425426
});
426427

427428
test("children([String])", function() {

0 commit comments

Comments
 (0)