X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fattributes.js;h=b3a49f50f869b8ec87f8bda334c397c291079106;hb=7b0b348419c85841671459b4d7153afc88d1fa83;hp=794da70ff6fda97e1910a53565bde8cd7ec20cbf;hpb=1e64d581830f735999b60939eccf9bcdcb2e9ef9;p=jquery.git diff --git a/src/attributes.js b/src/attributes.js index 794da70..b3a49f5 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -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 ) { @@ -263,12 +261,17 @@ 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 ); + var special = rspecialurl.test( name ), parent = elem.parentNode; - // 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" && 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