Bug Tracker

Modify

Ticket #546 (closed bug: fixed)

Opened 7 years ago

Last modified 5 years ago

option[@selected] not working in FF

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

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

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

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

Fixed in SVN.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.