Bug Tracker

Opened 17 years ago

Closed 17 years ago

Last modified 14 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:

Description

In FF, this expression:

$('option[@selected]')

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:

<html>
<head>
<script src="jquery-1.0.4.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
    $("#test").click( function() { 
       alert($("#mike option[@selected]").text()); 
    });
});
</script>
</head>
<body>
<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>
    </select>
</div></form>
</body>
</html>


Change History (2)

comment:1 Changed 17 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 17 years ago by joern

Resolution: fixed
Status: newclosed

Fixed in SVN.

Note: See TracTickets for help on using tickets.