Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#11488 closed bug (invalid)

Setting select attribute doesn't change dropdown position in firefox

Reported by: anonymous Owned by:
Priority: low Milestone: None
Component: attributes Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:

Description

Firefox 9 & 11 under Windows 7 Professional

The dropdown HTML:

<select id="periodSelect" name="periodSelect">
<option value="0" selected>Choose period</option>
<option value="9">2011, P01</option>
<option value="11">2012, P01</option>
<option value="2">011, P10</option>
<option value="1">2013, P01</option>
</select>

jquery code:
$('#periodSelect option').removeAttr('selected');
$("#periodSelect option[value='11']").attr('selected',true);

description: The code, when executed for the first time, doesn't chenge what I can se in the dropdown. When executed for the second time it makes the change. The change happens also when I select an option from the drop down and then execute the code.

working example (not working in Firefox):
http://jsfiddle.net/LXz8J/

The code works for latest version of chrome (17) and IE8

Change History (4)

comment:1 Changed 7 years ago by sindresorhus

Component: unfiledattributes
Priority: undecidedlow
Resolution: invalid
Status: newclosed

Not really a jQuery bug since it's reproducible using native DOM methods too (in Firefox, not Chrome): http://jsfiddle.net/scjK9/

To get it to work, you can remove the first line. You don't actually need to remove the 'selected' property before adding it to a option element. Just add it directly and the browser will be smart enough to switch to the recently selected option element.

comment:2 in reply to:  1 Changed 6 years ago by anonymous

Replying to sindresorhus:

Not really a jQuery bug since it's reproducible using native DOM methods too (in Firefox, not Chrome): http://jsfiddle.net/scjK9/

To get it to work, you can remove the first line. You don't actually need to remove the 'selected' property before adding it to a option element. Just add it directly and the browser will be smart enough to switch to the recently selected option element.

The code in the changed history is not working at all, so the bug is stell open!!!

comment:3 Changed 6 years ago by timmywil

@anonymous: use properties, not attributes. http://jsfiddle.net/timmywil/xyH32/

comment:4 Changed 5 years ago by anonymous

@timmywil: that was really good help for me to solve some weird behaviour appeared in Firefox 27.0, didn't even know that there were differences between attributes and properties (attr() vs prop())

Note: See TracTickets for help on using tickets.