Given is a nested list, with the following markup (and sadly can\'t be changed at this moment). I want to sort this list (and all nested lists by the \'a\'-tag title.) The firs
Sorting everything is a matter of appending all nodes to their respective parents in alphabetical order.
function uCase(elem) {
return $.trim( $(elem).text().toUpperCase() )
}
function compareFirstLink(a, b) {
var A = uCase( $(a).first('a') ),
B = uCase( $(b).first('a') );
return (A > B) ? 1 : -1;
}
$(function () {
var $sortables = $("ul:has(div:first-child), li:not(.fixedOrder)");
$sortables.sort(compareFirstLink).each(function () {
this.parentNode.appendChild(this);
});
});