From a00e63ea5a2c26f8e6384b5d1e2247be44c727e9 Mon Sep 17 00:00:00 2001 From: jeresig Date: Tue, 22 Dec 2009 15:46:54 -0500 Subject: [PATCH] Make a feature detect for the attribute selected code. Fixes #5702. --- src/attributes.js | 17 ++++++++++------- src/support.js | 6 +++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/attributes.js b/src/attributes.js index b3a49f50f..a2108feb8 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -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; + } } } diff --git a/src/support.js b/src/support.js index 976729828..3e9977278 100644 --- a/src/support.js +++ b/src/support.js @@ -8,7 +8,7 @@ id = "script" + now(); div.style.display = "none"; - div.innerHTML = "
a"; + div.innerHTML = "
a"; var all = div.getElementsByTagName("*"), a = div.getElementsByTagName("a")[0]; @@ -52,6 +52,10 @@ // (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, -- 2.39.5