You can adapt the function described here: How may I sort a list alphabetically using jQuery? and just change the sort function ('<
')
<div id="foo">
<div class="test" data-listing-price="30">30</div>
<div class="test" data-listing-price="62">62</div>
<div class="test" data-listing-price="11">11</div>
<div class="test" data-listing-price="43">43</div>
</div>
In your js (highest integer to lowest):
var div = $('#foo');
var listitems = div.children('div.test').get();
listitems.sort(function (a, b) {
return (+$(a).attr('data-listing-price') > +$(b).attr('data-listing-price')) ?
-1 : (+$(a).attr('data-listing-price') < +$(b).attr('data-listing-price')) ?
1 : 0;
})
$.each(listitems, function (idx, itm) { div.append(itm); });
http://jsfiddle.net/NfVxk/