 <p>You can sort the elements before adding them to the DOM and then add them; that should work.</p> <pre><code>var statecontent = ['&lt;option value="Texas" data-code="TX"&gt;Texas - TX&lt;/option&gt;', '&lt;option value="Washington" data-code="WA"&gt;Washington - WA&lt;/option&gt;', '&lt;option value="Maryland" data-code="MD"&gt;Maryland - MD&lt;/option&gt;']; statecontent.sort(function(a,b) { return $(a)[0].text == $(b)[0].text ? 0 : $(a)[0].text &lt; $(b)[0].text ? -1 : 1; }); </code></pre> <p>And you also need to use single quotes for your array elements as you are already using the double quotes for the attributes, or at least escape it in the attributes.</p> <p><a href="http://jsfiddle.net/fiddleyetu/n8bSV/2/" rel="nofollow"><strong>WORKING JSFIDDLE DEMO</strong></a></p>