Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#4998 closed bug (invalid)

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

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 (1)

comment:1 Changed 10 years ago by dmethvin

Resolution: invalid
Status: newclosed

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().

Note: See TracTickets for help on using tickets.