I have multiple elements with the attribute: data-percentage
, is there a way of sorting the elements into ascending order with the lowest value first using eit
For some reason, on Firefox 64.0.2, none of the answers worked for me. This is what worked in the end, a mixture of Joseph Silber and Jeaf Gilbert's answers:
var $wrapper = $('.testWrapper');
$wrapper.find('.test').sort(function(a, b) {
return +$(a).data('percentage') - +$(b).data('percentage');
})
.appendTo($wrapper);