Well, figured I'd offer a slightly different jQuery solution to your dilemma for other people looking for additional help.
If you have to use a script, might as well make it do everything (the following script takes 4.2ms to run, which seems pretty reasonable to me :-)
Essentially what the below is doing is taking your tabular-data and converting it to a multidimensional array.
1, 2, 3, 4
5, 6, 7, 8
9, 10, 11, 12
Becomes:
[[1,5,9],[2,6,10],[3,7,11],[4,8,12]]
Then, it's just a matter of having it rewrite your table based on the new array with a couple for-loops.
One thing to note, you would have to bind this to a media query or window.resize handler to get the acquired affect you're looking for. That is as easy as changing the on.click handler I have assigned.
Take a look! It's pretty nifty:
HTML:
<input type="button" id="switch" value="switch" \>
<table id="switchItems">
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
</tr>
<tr>
<td>...etc
jQuery Script:
$(function(){
$('#switch').on('click', function(){
var items = [];
var itemsConv = [];
var table = $('#switchItems');
var row,cell;
// FIND ALL OF THE DATA
$("tr").each(function(){
var trRow = [];
$(this).children().each(function() {
trRow.push($(this).text());
});
items.push(trRow);
});
for(var j=0;j<items[0].length;j++){
var newRow = [];
for(var i=0;i<items.length;i++){
newRow.push(items[i][j]);
}
itemsConv.push(newRow);
}
// KILL OUR CURRENT DATA IN THE TABLE
table.empty();
// REWRITE OUR TABLE WITH NEW DATA
for(var i=0; i<itemsConv.length; i++){
row = $( '<tr />' );
table.append( row );
for(var j=0; j<itemsConv[i].length; j++){
cell = $('<td>'+itemsConv[i][j]+'</td>');
row.append( cell );
}
}
});
});
Hope this was helpful!