Permalink
Browse files

Fixes #25. Make sure we only access parentNode if it's available.

  • Loading branch information...
1 parent 069085f commit 7c7e892472ba1464d449c42dffff38a652a0a277 @dmethvin dmethvin committed with jitter Dec 17, 2010
Showing with 12 additions and 1 deletion.
  1. +3 −1 sizzle.js
  2. +9 −0 test/unit/selector.js
View
@@ -595,7 +595,9 @@ var Expr = Sizzle.selectors = {
selected: function( elem ) {
// Accessing this property makes selected-by-default
// options in Safari work properly
- elem.parentNode.selectedIndex;
+ if ( elem.parentNode ) {
+ elem.parentNode.selectedIndex;
+ }
return elem.selected === true;
},
View
@@ -515,3 +515,12 @@ test("pseudo - form", function() {
t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c","option4b","option4c","option4d","option5a"] );
});
+
+test("disconnected nodes", function() {
+ expect(3);
+ var $opt = jQuery( '<option value="whipit">Whip It</option>' ).appendTo("#main").detach();
+ equal( $opt.val(), "whipit", "option value" );
+ equal( $opt.is(":selected"), false, "unselected option" );
+ $opt.attr("selected", true);
+ equal( $opt.is(":selected"), true, "selected option" );
+});

0 comments on commit 7c7e892

Please sign in to comment.