#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>
Note: See
TracTickets for help on using
tickets.
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:
That prevents it from using getAttribute and always uses the object's .selected property instead.
I think that also affects jQuery.expr:
should be changed to this: