title: Sort Select Options by Value Attribute Using jQuery
body: <p>Well, the title says it all. What I am doing is creating a featured product module. The drop down list of sizes is populated using JSON and I am using handlebars to render the html. I do not have control over the JSON file. I tried sorting the option values by the actual text within the option tags, but I realized that the option values were wrong after that. So now I am trying to sort the options by their value attributes, but haven't figured it out yet. I am trying to do something like this:</p>
  
  <pre><code>var selectList = $('#featuredSelectField option');
  var newList = [];
  var theNewNew = [];
  for(var i=0; i&lt;selectList.length; i++){
      newList[i]=(selectList[i].value);    
  }
  newList.sort();
  for(var i=0; i&lt;newList.length; i++){
      theNewNew[i] = $('#featuredSelectField option[value="'+newList[i]+'"]');
      selectList[i] = theNewNew[i];
  }
  </code></pre>
  
  <p>and here is the html:</p>
  
  <pre><code>&lt;select id="featuredSelectField" name="addid7617843" size="1"&gt;
      &lt;option value="" data-value=""&gt;Select an option&lt;/option&gt;
      &lt;option value="10493640" data-value="10493640" data-qty="30" data-mxqty="30"&gt;Size 5.5 - $111.99&lt;/option&gt;
      &lt;option value="10493639" data-value="10493639" data-qty="120" data-mxqty="50"&gt;Size 5 - $111.99&lt;/option&gt;
      &lt;option style="display: none;" disabled="disabled" value="10792504" data-value="10792504" data-qty="0" data-mxqty="0"&gt;Size 10 - $111.99 Sold Out&lt;/option&gt;
      &lt;option value="10493644" data-value="10493644" data-qty="138" data-mxqty="50"&gt;Size 7 - $111.99&lt;/option&gt;
      &lt;option value="10493642" data-value="10493642" data-qty="22" data-mxqty="22"&gt;Size 6.5 - $111.99&lt;/option&gt;                
      &lt;option value="10493641" data-value="10493641" data-qty="57" data-mxqty="50"&gt;Size 6 - $111.99&lt;/option&gt;              
      &lt;option value="10493648" data-value="10493648" data-qty="99" data-mxqty="50"&gt;Size 9 - $111.99&lt;/option&gt;      
      &lt;option value="10493647" data-value="10493647" data-qty="28" data-mxqty="28"&gt;Size 8.5 - $111.99&lt;/option&gt;                
      &lt;option value="10493646" data-value="10493646" data-qty="74" data-mxqty="50"&gt;Size 8 - $111.99&lt;/option&gt;                  
      &lt;option value="11288830" data-value="11288830" data-qty="1" data-mxqty="1"&gt;Size 4.5 - $111.99&lt;/option&gt;
      &lt;option value="10493645" data-value="10493645" data-qty="51" data-mxqty="50"&gt;Size 7.5 - $111.99&lt;/option&gt;                    
      &lt;option value="10792503" data-value="10792503" data-qty="5" data-mxqty="5"&gt;Size 9.5 - $111.99&lt;/option&gt;
      &lt;option value="11288831" data-value="11288831" data-qty="6" data-mxqty="6"&gt;Size 4 - $111.99&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>