<ul class="alphaList">
<li>apples</li>
<li>cats</li>
<li>bears</li>
</ul>
JavaScript/jQuery:
var elems = $('.alphalist li').detach().sort(function (a, b) {
return ($(a).text() < $(b).text() ? -1
: $(a).text() > $(b).text() ? 1 : 0);
});
$('.alphalist').append(elems);
Note: jQuery detach() gets (removing) elements from DOM.