I have a list as below that is created dynamically:
Below should do the trick:
$(function() {
$('button').click(function() {
var liContents = [];
$('ul li').each(function() {
liContents.push(parseInt($(this).text(), 10));
});
liContents.sort(numOrdDesc);
$('ul li').each(function() {
$(this).text(liContents.pop());
});
});
});
function numOrdDesc(a, b) {
return (b - a);
}
- 20
- 10
- 5
- 3
- 32
- 25
- 6
- 12
- 8