Skip to main content

Bug Tracker

Side navigation

#11564 closed bug (cantfix)

Opened April 06, 2012 05:46PM UTC

Closed April 07, 2012 01:57PM UTC

$('option').attr('selected', true) does not work on IE6

Reported by: kanonji Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: ie6 select option Cc:
Blocked by: Blocking:
Description

jQuery version

Error occurs

1.7.0 1.7.1 1.7.2

I tried

1.7.0 1.7.1 1.7.2

Browser

  • Error occurs on IE6.
  • No any errors on Chrome 18.0.1025.142

OS

  • Windows XP

Test case

http://jsdo.it/kanonji/oqyJ

Description

If there are no option element when the html is loaded, $('option').attr('selected', true) does not work on IE6.

Step by step

Does not work

1. Open IE6

2. Select element with no option element like '<select></select>' on the html.

3. Append/prepend some option elements with jQuery in the select element.

4. attr('selected', true) for the option element appended step 3 above

5. The error occurs.

work

1. Open IE6

2. Select element with some option elements.

3. Do nothing or $('select').empty().

4. Append/prepend some option elements with jQuery in the select element.

5. attr('selected', true) for the option element appended step 4 above

6. Work.

Attachments (0)
Change History (1)

Changed April 07, 2012 01:57PM UTC by dmethvin comment:1

keywords: → ie6 select option
resolution: → cantfix
status: newclosed

The site jsdo.it does not work for me in IE6. This JSFiddle reproduces the issue:

http://jsfiddle.net/dmethvin/SVTUm/

This is a well-known issue with IE6 being unable to update options, and can be fixed with setTimeout or one of the solutions suggested in the links below:

http://jsfiddle.net/dmethvin/SVTUm/1/

Because it is a timing issue it can't be fixed within jQuery core without introducing even more issues (e.g., what if other things run before we select the option in the timeout?)

http://stackoverflow.com/questions/779379/why-does-settimeoutfn-0-sometimes-help

http://stackoverflow.com/questions/3737128/jquery-select-option-list-not-updated-fast-enough-in-ie6