Make sure that selected works in Safari on options in optgroups. Fixes #5701.

This commit is contained in:
jeresig 2009-12-22 15:02:52 -05:00
parent baff0b0c85
commit 4729f4d443
2 changed files with 15 additions and 4 deletions

View file

@ -261,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
// 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