Bug Tracker

Modify

Ticket #11564 (closed bug: cantfix)

Opened 14 months ago

Last modified 14 months ago

$('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:
Blocking: Blocked by:

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

comment:1 Changed 14 months ago by dmethvin

  • Keywords ie6 select option added
  • Status changed from new to closed
  • Resolution set to cantfix

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.