http://jsfiddle.net/nicktheandroid/6BAfH/1/
The list-elements are sorted accordingly by the number in their span. Why is it that the last few numbers are out of order? I’m confused.
Jquery
function sortEm(a,b){
return parseInt($('span', a).text()) < parseInt($('span', b).text()) ? 1 : -1;
}
$('li').sort(sortEm).prependTo($('ul#test'));
HTML
<ul id="test">
<li> Cups
<span>12</span>
</li>
<li> Plates
<span>18</span>
</li>
<li> Forks
<span>03</span>
</li>
<li> Knives
<span>08</span>
</li>
<li> Bowls
<span>55</span>
</li>
</ul>
Welcome to the world of octal numbers.
Use the radix to base 10 with parseInt.