This question is similar to this one http://stackoverflow.com/questions/317095/how-do-i-add-options-to-a-dropdownlist-using-jquery but I would like to add it in an ordered fashion. The example in the other question just adds it to the end of the list. The code is as follows:
var myOptions = {
1: "Test"
2: "Another"
};
$.each(myOptions, function(val, text) {
$('#Projects').append(
$('<option></option').val(val).html(text)
);
});
Suppose the list already contains 3 items: "Blah", "Foo" and "Zebra". I'd like to be able to add the two new options ("Test" and "Another") to the dropdown so it's ordered ("Another", "Blah", "Foo", "Test" and "Zebra") using jQuery.
Any help is much appreciated!!!