Badbart
Badbart

Reputation: 3

jquery sort by id element (IE bug)

Internet Explorer makes me crazy. Why won't this script work on IE?: http://jsfiddle.net/THMu3/

HTML:

<ul id="cat">
<li id="3">Text 3</li>
<li id="1">Text 1</li>
<li id="2">Text 2</li>

JS:

$("#cat li").sort(function (a, b) {
return parseInt(a.id) > parseInt(b.id);}).each(function(){
var elem = $(this);
elem.remove();
$(elem).appendTo("#cat");})

Upvotes: 0

Views: 167

Answers (1)

renakre
renakre

Reputation: 8291

The solution is very simple actually. Change this

return parseInt(a.id) > parseInt(b.id)

to this

return parseInt(a.id) - parseInt(b.id)

Check here for more information: https://stackoverflow.com/a/949970/1845408

Upvotes: 1

Related Questions