Skip to content
Permalink
Browse files

Fix #11370: .siblings() shouldn't throw exception on a detached element

  • Loading branch information...
gibson042 authored and dmethvin committed Feb 22, 2012
1 parent 7226cf2 commit a619cb3063c104aa5ec808e13d2c84af565eacc6
Showing with 3 additions and 2 deletions.
  1. +1 −1 src/traversing.js
  2. +2 −1 test/unit/traversing.js
@@ -204,7 +204,7 @@ jQuery.each({
return jQuery.dir( elem, "previousSibling", until );
},
siblings: function( elem ) {
return jQuery.sibling( elem.parentNode.firstChild, elem );
return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
},
children: function( elem ) {
return jQuery.sibling( elem.firstChild );
@@ -414,14 +414,15 @@ test("andSelf()", function() {
});

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

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

1 comment on commit a619cb3

@sidcool1234

This comment has been minimized.

Copy link

sidcool1234 commented on a619cb3 Mar 22, 2012

Perfect fix.

Please sign in to comment.
You can’t perform that action at this time.