Edit: I am not reading the original question correctly. This example will go through all the cells in the table, first ordered by their cells.
Markup
<table class='sortable'> <tr> <td>a</td> <td>d</td> <td>g</td> </tr> <tr> <td>b</td> <td>e</td> <td>h</td> </tr> <tr> <td>c</td> <td>f</td> <td>i</td> </tr> </table>
JQuery
var cells = $('table.sortable td').sort(function(a, b) { //compare the cell index var c0 = $(a).index(); var c1 = $(b).index(); if (c0 == c1) { //compare the row index if needed var r0 = $(a).parent().index(); var r1 = $(b).parent().index(); return r0 - r1; } else return c0 - c1; }); //console.log(cells); cells.each(function() { console.log($(this).html()); });
Result:
a b c d e f g h i
wsanville
source share