Skip to content

Instantly share code, notes, and snippets.

@bxt
Created April 11, 2011 23:04
Show Gist options
  • Save bxt/914568 to your computer and use it in GitHub Desktop.
Save bxt/914568 to your computer and use it in GitHub Desktop.
Sorting HTML-Tables (or anything) using jQuery and Javascript's native Array.prototype.sort
var tableRows=$("tr").detach();
Array.prototype.sort.call(tableRows,function(a,b){
// Compare two table rows by the numeric value of their first <td>
return a.firstChild.firstChild.nodeValue*1 < b.firstChild.firstChild.nodeValue*1
});
$("table").append(tableRows);
// Tested in Firefox 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment