Skip to content

Instantly share code, notes, and snippets.

@jasonlong
Created June 17, 2011 19:22
Show Gist options
  • Save jasonlong/1032098 to your computer and use it in GitHub Desktop.
Save jasonlong/1032098 to your computer and use it in GitHub Desktop.
Adding a class to <td> elements with jquery.tablesorter.js
$('table.sortable').tablesorter();
$('table.sortable th').bind('click', function() {
// remove sorted class from all table cells and start fresh
$(this).closest('table').find('td.sorted').removeClass('sorted');
// find out which column was clicked and add the sorted class to
// the <td> cells below it
var index = $(this).prevAll().length;
$(this).closest('table').find('tr').each(function(row) {
var cell = $(this).find('td:nth-child(' + parseInt(index+1) + ')').addClass('sorted');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment