Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#546 closed bug (fixed)

option[@selected] not working in FF

Reported by: malsup Owned by:
Priority: major Milestone:
Component: core Version:
Keywords: Cc:
Blocked by: Blocking:


In FF, this expression:


never finds any elements. This used to work properly in early versions of jQuery. I've confirmed that this works in v62 but not in any 1.0 or later version.

Mail thread: http://jquery.com/discuss/2006-December/019856/

Test page:

<script src="jquery-1.0.4.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
    $("#test").click( function() { 
       alert($("#mike option[@selected]").text()); 
<form name="foo"><div>
    <input type="button" id="test" value="Test" />
    <select name="zip" id="mike">
        <option value="1">one</option>
        <option value="2">two</option>
        <option value="3">three</option>

Change History (2)

comment:1 Changed 9 years ago by Dave

Notice that none of the elements are selected. If you add a selected="selected" attribute to one of the elements it returns that option's text regardless of the dynamic value.

The problem seems to be fixed by adding this to the fix object in jQuery.attr:

selected: "selected",

That prevents it from using getAttribute and always uses the object's .selected property instead.

I think that also affects jQuery.expr:

selected: "a.selected | | jQuery.attr(a, 'selected')",

should be changed to this:

selected: "a.selected",

comment:2 Changed 9 years ago by joern

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

Fixed in SVN.

Note: See TracTickets for help on using tickets.