aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2012-02-22 00:21:18 -0500
committerDave Methvin <dave.methvin@gmail.com>2012-02-23 22:40:07 -0500
commita619cb3063c104aa5ec808e13d2c84af565eacc6 (patch)
tree37731dfd6626427e55b3e8e15a1f09130fdd8f32
parent7226cf2800315e90b671db63f2b5f51150ad7e8e (diff)
downloadjquery-a619cb3063c104aa5ec808e13d2c84af565eacc6.tar.gz
jquery-a619cb3063c104aa5ec808e13d2c84af565eacc6.zip
Fix #11370: .siblings() shouldn't throw exception on a detached element
-rw-r--r--src/traversing.js2
-rw-r--r--test/unit/traversing.js3
2 files changed, 3 insertions, 2 deletions
diff --git a/src/traversing.js b/src/traversing.js
index c342e15c1..08c95ec4a 100644
--- a/src/traversing.js
+++ b/src/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 );
diff --git a/test/unit/traversing.js b/test/unit/traversing.js
index 63d46dd45..8e8b5360a 100644
--- a/test/unit/traversing.js
+++ b/test/unit/traversing.js
@@ -414,7 +414,7 @@ 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)" );
@@ -422,6 +422,7 @@ test("siblings([String])", function() {
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() {