<script type="text/javascript">$.fn.sortChildren = function() { return $(this).each(function(i,ul){ $(ul).children().sort(function(a,b){ return $(a).text() > $(b).text(); }).each(function(idx,obj){ // move each element to the end in order $(ul).append($(obj)); }); });};$( document ).ready(function() { $('ul').append('<li>Mangos</li>'); $('ul').sortChildren();});</script>
Open in new window
I also made a jsFiddle to show some more options: https://jsfiddle.net/robert_schutt/jjf63utu/