Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Forked from pepebe/transpose_table.js
Created November 16, 2012 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/4091869 to your computer and use it in GitHub Desktop.
Save steveosoule/4091869 to your computer and use it in GitHub Desktop.
JS: Transpose HTML table using jQuery
$(function() {
var t = $('#thetable tbody').eq(0);
var r = t.find('tr');
var cols= r.length;
var rows= r.eq(0).find('td').length;
var cell, next, tem, i = 0;
var tb= $('<tbody></tbody>');
while(i<rows){
cell= 0;
tem= $('<tr></tr>');
while(cell<cols){
next= r.eq(cell++).find('td').eq(0);
tem.append(next);
}
tb.append(tem);
++i;
}
$('#thetable').append(tb);
$('#thetable').show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment