I have searched and tried hard to achieve this but completely stuck and hoping somebody on here can help. Basically I would like to be able to click on a button and use jQuery to sort an unordered list alphabetically by group heading and then each nested list alphabetically within each group. Many thanks in advance and here goes...
The default list:
<ul id="list">
<li><a href="#" rel="Meat">Lamb</a></li>
<li><a href="#" rel="Meat">Pork</a></li>
<li><a href="#" rel="Meat">Beef</a></li>
<li><a href="#" rel="Fruit and Vegetables">Banana</a></li>
<li><a href="#" rel="Fruit and Vegetables">Orange</a></li>
<li><a href="#" rel="Fruit and Vegetables">Cabbage</a></li>
</ul>
Click a button and then sort the list to something like this:
<ul id="list">
<li class="grouphead">Fruit and Vegetables</li>
<ul>
<li><a href="#" rel="Fruit and Vegetables">Banana</a></li>
<li><a href="#" rel="Fruit and Vegetables">Cabbage</a></li>
<li><a href="#" rel="Fruit and Vegetables">Orange</a></li>
</ul>
<li class="grouphead">Meat</li>
<ul>
<li><a href="#" rel="Meat">Beef</a></li>
<li><a href="#" rel="Meat">Lamb</a></li>
<li><a href="#" rel="Meat">Pork</a></li>
</ul>
</ul><!-- End: #list -->
http://jsfiddle.net/r5QQT/7/
I modified your HTML a little bit to make selection simpler in this answer:
Here is it in a Fiddle: http://jsfiddle.net/r5QQT/1/