I have some items in a div that are have the data attribute of data-order attached to them:
<div class="list">
<a href="#" data-order="4">Thing 4</a>
<a href="#" data-order="3">Thing 3</a>
<a href="#" data-order="1">Thing 1</a>
<a href="#" data-order="2">Thing 2</a>
</div>
But I'm trying to get them so they display the numerical order (ascending - 1,2,3, etc.):
<div class="list">
<a href="#" data-order="1">Thing 1</a>
<a href="#" data-order="2">Thing 2</a>
<a href="#" data-order="3">Thing 3</a>
<a href="#" data-order="4">Thing 4</a>
</div>
I have this:
$(".list a").sort(function(a, b) {
return $(a).attr("data-order") > $(b).attr("data-order");
}).each(function() {
$(".list").prepend(this);
});
But that seems to really mess the order up. So I'm not too sure what I'm doing incorrectly or if there might be a simpler way to go about getting them to sort correctly.
new Dateto accomplish?new Date