]> source.dussan.org Git - jquery.git/commitdiff
Make a feature detect for the attribute selected code. Fixes #5702.
authorjeresig <jeresig@gmail.com>
Tue, 22 Dec 2009 20:46:54 +0000 (15:46 -0500)
committerjeresig <jeresig@gmail.com>
Tue, 22 Dec 2009 20:46:54 +0000 (15:46 -0500)
src/attributes.js
src/support.js

index b3a49f50f869b8ec87f8bda334c397c291079106..a2108feb85c71320b0b9c7ee98a89478302c9845 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;
+                                       }
                                }
                        }
 
index 97672982878d65fae60c2c5ad0ecfd5cc30617f2..3e99772785de49f38867211a965ddf3b72de0efb 100644 (file)
@@ -8,7 +8,7 @@
                id = "script" + now();
 
        div.style.display = "none";
-       div.innerHTML = "   <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><select><option>text</option></select><input type='checkbox'/>";
+       div.innerHTML = "   <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
 
        var all = div.getElementsByTagName("*"),
                a = div.getElementsByTagName("a")[0];
                // (WebKit defaults to "" instead)
                checkOn: div.getElementsByTagName("input")[0].value === "on",
 
+               // Make sure that a selected-by-default option has a working selected property.
+               // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
+               optSelected: document.createElement("select").appendChild( document.createElement("option") ).selected,
+
                // Will be defined later
                scriptEval: false,
                noCloneEvent: true,