0

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.

Here is a jsfiddle example.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ogelami
  • 366
  • 1
  • 14

1 Answers1

2

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.

Ogelami
  • 366
  • 1
  • 14