Bug Tracker

Modify

Ticket #4998 (closed bug: invalid)

Opened 4 years ago

Last modified 14 months ago

attr("selected", true) fails in IE6

Reported by: scottamain Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: IE6, selected Cc:
Blocking: Blocked by:

Description

In my script, I'm finding an <option> element and setting it to be selected.

The following code fails in IE6:

var selectedItem = $("#Control option[value='"+selectedLevel+"']"); selectedItem.attr("selected","true");

This code, however, works in IE6 (and all browsers):

var selectedItem = $("#Control option[value='"+selectedLevel+"']").get(0); selectedItem.setAttribute('selected',true);

So the normal DOM function "setAttribute" is more successful than jQuery, which I suspect is using the (known-to-fail in IE6) "selected" field (as in, selectedItem.selected = true)... that fails in IE6 the same as my jquery sample above.

I'm using v1.3.2

Change History

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

You should be using:

selectedItem.attr("selected",true);

That's always worked for me on all browsers. Since the option element has a selected property, it's used in preference to the html attribute when you try to set it with .attr().

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.