1

The following code does not work on Safari mobile:

$("#button").click(function() {
    $("fieldset").each(function() {
        $(this).children(".input").detach().sort(function(a, b) {
            return $(a).attr("data-sort") < $(b).attr("data-sort");
        }).appendTo(this);
    });
});

The html looks somewhat like this:

<fieldset>
    <span class='input' data-sort='3'><input>.....</input></span>
    <span class='input' data-sort='1'><input>.....</input></span>
    <span class='input' data-sort='2'><input>.....</input></span>
</fieldset>

It works just fine on desktop. Any ideas of what's going on?

Robin Mackenzie
  • 18,801
  • 7
  • 38
  • 56
Evan
  • 37
  • 4

1 Answers1

0

Fixed it. The callback function for .sort() was badly designed.

$("#button").click(function() {
    $("fieldset").each(function() {
        $(this).children(".input").detach().sort(function(a, b) {
            var contentA =parseInt( $(a).attr('data-sort'));
            var contentB =parseInt( $(b).attr('data-sort'));
            return (contentA < contentB) ? -1 : (contentA > contentB) ? 1 : 0;
        }).appendTo(this);
    });
});
Evan
  • 37
  • 4