Make a feature detect for the attribute selected code. Fixes #5702.
[jquery.git] / src / attributes.js
index b3a49f5..a2108fe 100644 (file)
@@ -261,16 +261,19 @@ jQuery.extend({
                // Only do all the following if this is a node (faster for style)
                if ( elem.nodeType === 1 ) {
                        // These attributes require special treatment
-                       var special = rspecialurl.test( name ), parent = elem.parentNode;
+                       var special = rspecialurl.test( name );
 
                        // Safari mis-reports the default selected property of an option
                        // Accessing the parent's selectedIndex property fixes it
-                       if ( name === "selected" && parent ) {
-                               parent.selectedIndex;
-
-                               // Make sure that it also works with optgroups, see #5701
-                               if ( parent.parentNode ) {
-                                       parent.parentNode.selectedIndex;
+                       if ( name === "selected" && !jQuery.support.optSelected ) {
+                               var parent = elem.parentNode;
+                               if ( parent ) {
+                                       parent.selectedIndex;
+       
+                                       // Make sure that it also works with optgroups, see #5701
+                                       if ( parent.parentNode ) {
+                                               parent.parentNode.selectedIndex;
+                                       }
                                }
                        }