Reputation: 67
Im using Jquery UI to get users to sort a list. I have a button to show answers if they want, which will put the list in order, based on ID. The function that sorts the list is:
function show_order() {
var elems = $('#sortable').children('li').remove();
elems.sort(function(a,b){
return parseInt(a.id) > parseInt(b.id);
});
$('#sortable').append(elems);
}
This works fine in Chrome and Firefox, but not in IE (11) - with no error in console.
See http://jsfiddle.net/bvacK/ for example.
Upvotes: 3
Views: 107
Reputation: 129832
.sort
expects you to return a value less than 0 (a
less than b
), 0 (equal) or a value greater than 0 (a
greater than b
). Simply returning the result of a >
comparison will yield a boolean. Change your code accordingly:
return parseInt(a.id, 10) - parseInt(b.id, 10);
Upvotes: 3