[jQuery] Appending <option> to <select>

[jQuery] Appending <option> to <select>

Hi All,
I'm new to jquery but like what I see so far.
I have an array of strings that I'd like to add to a <select> element
as <option> elements.
HTML:
<select id="routeSelect">
</select>
JavaScript:
for(var i = 0; i < routes.length; ++i) {
$("#routeSelect").append("<option value=\""
+ routes[i] +"\">"+ routes[i] +"</option>");
}
The above code appears to just append the text to the select element
without creating the child option elements. Viewing the generated
source (in Web Developer in Firefox) shows htm like: <select
id="routeSelect">abcdef</select>
However, the following code (more "old school") seems to work fine.
var routeSelect = $("#routeSelect").get(0);
for(var i = 0; i < routes.length; ++i) {
routeSelect.options[i + 1] = new Option(
routes[i],
routes[i]);
}
I'm using firefox under Mac OSX though it looks like the same behavior
under safari and opera.
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/