title: Sorting Divs in jQuery by Custom Sort Order
body: <p>I'm trying to re-sort the child elements of the tag <code>input</code> by comparing
  their category attribute to the category order in the Javascript
  variable <code>category_sort_order</code>. Then I need to remove divs whose category attribute
  does not appear in <code>category_sort_order</code>.</p>
  
  <p>The expected result should be:</p>
  
  <blockquote>
    <p>any<br>
    product1<br>
    product2<br>
    download</p>
  </blockquote>
  
  <p>The code:</p>
  
  <pre><code>&lt;div id="input"&gt;
  &lt;div category="download"&gt;download&lt;/div&gt;
  &lt;div category="video"&gt;video1&lt;/div&gt;
  &lt;div category="video"&gt;video2&lt;/div&gt;
  &lt;div category="product"&gt;product1&lt;/div&gt;
  &lt;div category="any"&gt;any&lt;/div&gt;
  &lt;div category="product"&gt;product2&lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  var category_sort_order = ['any', 'product', 'download'];
  &lt;/script&gt;
  </code></pre>
  
  <p>I really don't even know where to begin with this task but if you could please provide any assistance whatsoever I would be extremely grateful.</p>