Outcomes Tracker Sort by Last Name
function sort() {
var names = Array.from( document.querySelectorAll('.student-name') );
names.sort(function(a, b) {
var a = a.textContent.trim().split(' ')[1];
var b = b.textContent.trim().split(' ')[1];
return a == b ? 0 : (a < b ? -1 : 1);
});
var list = document.querySelector('.outcomes-table');
names.forEach(function(name){
var tag = name;
while( !tag.parentNode.classList.contains('row') ){
tag = tag.parentNode;
}
tag = tag.parentNode;
list.appendChild(tag);
});
}
sort();
Bookmarklet
<a href="javascript:(function()%7Bfunction%20sort()%20%7Bvar%20names%20%3D%20Array.from(%20document.querySelectorAll('.student-name')%20)%3Bnames.sort(function(a%2C%20b)%20%7Bvar%20a%20%3D%20a.textContent.trim().split('%20')%5B1%5D%3Bvar%20b%20%3D%20b.textContent.trim().split('%20')%5B1%5D%3Breturn%20a%20%3D%3D%20b%20%3F%200%20%3A%20(a%20%3C%20b%20%3F%20-1%20%3A%201)%3B%7D)%3Bvar%20list%20%3D%20document.querySelector('.outcomes-table')%3Bnames.forEach(function(name)%7Bvar%20tag%20%3D%20name%3Bwhile(%20!tag.parentNode.classList.contains('row')%20)%7Btag%20%3D%20tag.parentNode%3B%7Dtag%20%3D%20tag.parentNode%3Blist.appendChild(tag)%3B%7D)%3B%7Dsort()%7D)()">Sort by Last Name</a>