title: Javascript/jQuery: Reordering divs according to data-attribute values
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/14160498/sort-element-by-numerical-value-of-data-attribute">Sort element by numerical value of data attribute</a>  </p>
  </blockquote>
  
  
  
  <p>I want to reorganize divs according to a data attribute set on them, ranging from highest integer to lowest. Right now, I push all the data into an array and sort that but I'm not sure how to proceed. How can I use this to reorganize divs inside their parent div?</p>
  
  <pre><code>var prices = new Array();
  $(this).children('.listing-item').each(function() {
      var price = parseInt($(this).attr('data-listing-price'));
      prices.push(price)
  });
  prices.sort(function(a,b){return b-a});
  </code></pre>
  
  <p>This gets me an array like 139,129,129,109,109,84 for example. Now my idea was to loop through the divs another time with a selector like this:</p>
  
  <pre><code>$('.listing-item[data-listing-price="' + prices[0] + '"]')
  </code></pre>
  
  <p>but I'm not sure how to move the divs (the div with the highest data-attribute integer should move to the top and so on. Any idea?</p>