Bug Tracker

Opened 8 years ago

Closed 8 years ago

#11564 closed bug (cantfix)

$('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.

Change History (1)

comment:1 Changed 8 years ago by dmethvin

Keywords: ie6 select option added
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

Note: See TracTickets for help on using tickets.