How can I sort the data in a dynamically generated SELECT element with jQuery? I don't understand what you mean by "the order is undefined". If you look at the example, the order is very clearly, the val portion as opposed to the html portion. This is consistent regardless of the order that I generate the list, the order will always by based on the val.