<p>I'm looking for some sample code that will sort the list items in an HTML list by alphabetical order.  Can anyone help?</p>

<p>Here is a sample list for people to work with:</p>

<pre><code>&lt;ul class="alphaList"&gt;
    &lt;li&gt;apples&lt;/li&gt;
    &lt;li&gt;cats&lt;/li&gt;
    &lt;li&gt;bears&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

```
```
var items = $('.alphaList > li').get();
items.sort(function(a,b){
  var keyA = $(a).text();
  var keyB = $(b).text();

  if (keyA < keyB) return -1;
  if (keyA > keyB) return 1;
  return 0;
});
var ul = $('.alphaList');
$.each(items, function(i, li){
  ul.append(li); /* This removes li from the old spot and moves it */
});
```
```