title: Sorting Select box with jQuery
body: <p>I have a select box on a form, which carries an incremental rel attribute.
  I have a function that can sort the options by thier .text() value, into alphabetcal order.</p>
  
  <p>My question is, with jQuery, how do i sort in an ascending order using the rel attribute ? </p>
  
  <pre><code>&lt;option rel="1" value="ASHCHRC"&gt;Ashchurch for Tewkesbury &lt;/option&gt;
  &lt;option rel="2" value="EVESHAM"&gt;Evesham &lt;/option&gt;
  &lt;option rel="3" value="CHLTNHM"&gt;Cheltenham Spa &lt;/option&gt;
  &lt;option rel="4" value="PERSHOR"&gt;Pershore &lt;/option&gt;
  &lt;option rel="5" value="HONYBRN"&gt;Honeybourne &lt;/option&gt;
  &lt;option rel="6" value="MINMARS"&gt;Moreton-in-Marsh &lt;/option&gt;
  &lt;option rel="7" value="GLOSTER"&gt;Gloucester &lt;/option&gt;
  &lt;option rel="8" value="GTMLVRN"&gt;Great Malvern &lt;/option&gt;
  &lt;option rel="9" value="MLVRNLK"&gt;Malvern Link &lt;/option&gt;
  </code></pre>
  
  <p>my sort function:  var object; can be one of many select boxes throughout the form.</p>
  
  <pre><code>$(object).each(function() {
  
      // Keep track of the selected option.
      var selectedValue = $(this).val();
  
      // sort it out
      $(this).html($("option", $(this)).sort(function(a, b) { 
          return a.text == b.text ? 0 : a.text &lt; b.text ? -1 : 1 
      }));
  
      // Select one option.
      $(this).val(selectedValue);
  
  });
  </code></pre>