$('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'); }); });