title: Sort DOM elements to order array with jQuery
body: <p>A moment ago I asked this question:
  <a href="https://stackoverflow.com/questions/13148941/javascript-sort-array-to-align-with-order-array/13148972">javascript sort array to align with order array</a> based on what turned out to be a false premise. (I've been up for too long, give me a break please).</p>
  
  <p>What I really need to do is sort DOM elements. <strong>Performance is key</strong> in my application as it will be running in very CPU-poor situations. So what I have is something like this:</p>
  
  <pre><code>&lt;div id="moduleWrap"&gt;
      &lt;div class="module"&gt;Jack&lt;/div&gt;    &lt;!-- 0 --&gt;
      &lt;div class="module"&gt;Jill&lt;/div&gt;    &lt;!-- 1 --&gt;
      &lt;div class="module"&gt;Nancy&lt;/div&gt;   &lt;!-- 2 --&gt;
      &lt;div class="module"&gt;Tom&lt;/div&gt;     &lt;!-- 3 --&gt;
      &lt;div class="module"&gt;Cartman&lt;/div&gt; &lt;!-- 4 --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And in JavaScript:</p>
  
  <pre><code>$modules = $('#moduleWrap .module');
  order    = [3,1,4,0,2];
  </code></pre>
  
  <p>What I need is this:</p>
  
  <pre><code>&lt;div id="moduleWrap"&gt;
      &lt;div class="module"&gt;Tom&lt;/div&gt;     &lt;!-- 3 --&gt;
      &lt;div class="module"&gt;Jill&lt;/div&gt;    &lt;!-- 1 --&gt;
      &lt;div class="module"&gt;Cartman&lt;/div&gt; &lt;!-- 4 --&gt;
      &lt;div class="module"&gt;Jack&lt;/div&gt;    &lt;!-- 0 --&gt;
      &lt;div class="module"&gt;Nancy&lt;/div&gt;   &lt;!-- 2 --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I thought (wrongly) that I could sort the jQuery object and simply append the result. This is not so.</p>