I need to be able to sort a list of divs based on the data-price attribute of a sub element. This is my markup:
-
If you want to place them in the body, you could do this:
function sorter(a, b) {
return a.getAttribute('data-price') - b.getAttribute('data-price');
};
var sortedDivs = $(".terminal").toArray().sort(sorter);
$(".container").remove(); //removing the old values
$.each(sortedDivs, function (index, value) {
$('body').append(value); //adding them to the body
});
Living demo: http://jsfiddle.net/a2TzL/1/