Sorting Content (client side!)
Jul 07
If you’ve got some content organized on your page, but you want it to be in a different order, here’s a quick fix:
//grab elements (in this case, all elements with class="bl"
var tasksC = $$('.bl');
//reorder on page in alpha
tasksC.sort(sortByTitleText);
//add back in new order
$$(tasksC).each(function(el){
el.inject($('catList'));
});
function sortByTitleText(a, b) {
/*
the value you're sorting can also be innerHTML. Mine had special formatting, so just using the text itself.
*/
var x = a.textContent;
var y = b.textContent;
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}