diff options
Diffstat (limited to 'src/attributes/val.js')
-rw-r--r-- | src/attributes/val.js | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/attributes/val.js b/src/attributes/val.js index 7af79cfef..d4ed96f31 100644 --- a/src/attributes/val.js +++ b/src/attributes/val.js @@ -78,10 +78,13 @@ jQuery.extend( { valHooks: { option: { get: function( elem ) { + var val = jQuery.find.attr( elem, "value" ); + return val != null ? + val : - // Support: IE<11 - // option.value not trimmed (#14858) - return jQuery.trim( elem.value ); + // Support: IE10-11+ + // option.text throws exceptions (#14686, #14858) + jQuery.trim( jQuery.text( elem ) ); } }, select: { @@ -100,8 +103,7 @@ jQuery.extend( { for ( ; i < max; i++ ) { option = options[ i ]; - // Support: IE<10 - // IE8-9 doesn't update selected after form reset (#2551) + // oldIE doesn't update selected after form reset (#2551) if ( ( option.selected || i === index ) && // Don't return options that are disabled or in a disabled optgroup @@ -135,11 +137,24 @@ jQuery.extend( { while ( i-- ) { option = options[ i ]; - if ( - option.selected = - jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 - ) { - optionSet = true; + + if ( jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0 ) { + + // Support: IE6 + // When new option element is added to select box we need to + // force reflow of newly added node in order to workaround delay + // of initialization properties + try { + option.selected = optionSet = true; + + } catch ( _ ) { + + // Will be executed only in IE6 + option.scrollHeight; + } + + } else { + option.selected = false; } } |