What about getting all of the list items, push them into array which later will be sorted?
var allListElements = document.getElementById("staff").getElementsByTagName("li");
var staff = new Array();
for (i = 0; i < allListElements.length; i++) {
staff.push(allListElements[i].getAttribute('data-azsort'));
}
staff.sort(function(a, b) {
if (a < b) return -1;
if (a > b) return 1;
return 0;
});
//Print
document.write('Sorted
');
for (i = 0; i < staff.length; i++) {
document.write(staff[i] + "
");
}
Input
-
John Smith
Professor
-
Tom Barnes
Lecturer
Additionally you can save the index of and reorder the .