Reputation: 365
I have a div with elements inside that i would like to sort by data value.
$('div#mainFrame div.element-container').sort(function(a, b)
{
return parseInt($(a).data('price')) < parseInt($(b).data('price'));
})
.appendTo('div#mainFrame');
I've tried it with chrome/firefox(pc) where it works perfectly fine, however it does not work with safari nor does it work with the android browser.
Upvotes: 0
Views: 576
Reputation: 365
I found a solution to the problem.
$('div#mainFrame div.element-container').sort(function(a, b)
{
return parseInt($(b).data('price')) - parseInt($(a).data('price'));
})
.appendTo('div#mainFrame');
The reason for this is that the sort expects a number, not a boolean return value.
Upvotes: 2