Make a feature detect for the attribute selected code. Fixes #5702.
[jquery.git] / src / attributes.js
index 794da70..a2108fe 100644 (file)
@@ -171,9 +171,7 @@ jQuery.fn.extend({
                                var values = jQuery.makeArray(val);
 
                                jQuery( "option", this ).each(function() {
-                                       // IE 6 will return "" for the value if one isn't specified, instead of the text
-                                       var node = this.getAttributeNode("value");
-                                       this.selected = jQuery.inArray( node && node.specified ? node.value : this.value || this.text, values ) >= 0;
+                                       this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;
                                });
 
                                if ( !values.length ) {
@@ -265,10 +263,18 @@ jQuery.extend({
                        // These attributes require special treatment
                        var special = rspecialurl.test( name );
 
-                       // Safari mis-reports the default selected property of a hidden option
+                       // Safari mis-reports the default selected property of an option
                        // Accessing the parent's selectedIndex property fixes it
-                       if ( name === "selected" && elem.parentNode ) {
-                               elem.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;
+                                       }
+                               }
                        }
 
                        // If applicable, access the attribute via the DOM 0 way