Skip to main content

Bug Tracker

Side navigation

#11488 closed bug (invalid)

Opened March 20, 2012 11:43AM UTC

Closed March 22, 2012 12:19AM UTC

Last modified February 28, 2014 08:32PM UTC

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

Attachments (0)
Change History (4)

Changed March 22, 2012 12:19AM UTC by sindresorhus comment:1

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.

Changed May 04, 2013 05:20PM UTC by anonymous comment:2

Replying to [comment:1 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!!!

Changed May 05, 2013 03:11AM UTC by timmywil comment:3

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

Changed February 28, 2014 08:32PM UTC by anonymous comment:4

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