How to invert (transpose) the rows and columns of an HTML table?
There is this a CSS solution by David Bushell (using flexbox): http://dbushell.com/2016/03/04/css-only-responsive-tables/
And there is also this CSS solution (using float)
tr { display: block; float: left; }
th, td { display: block; }
http://jsfiddle.net/XKnKL/3/
(they are both mentioned in this answer: HTML Table with vertical rows)
http://jsfiddle.net/CsgK9/2/
html:
<table>
<tr>
<td>1</td>
<td>4</td>
<td>7</td>
</tr>
<tr>
<td>2</td>
<td>5</td>
<td>8</td>
</tr>
<tr>
<td>3</td>
<td>6</td>
<td>9</td>
</tr>
</table>
<p><a href="#">Do it.</a></p>
js:
$("a").click(function(){
$("table").each(function() {
var $this = $(this);
var newrows = [];
$this.find("tr").each(function(){
var i = 0;
$(this).find("td").each(function(){
i++;
if(newrows[i] === undefined) { newrows[i] = $("<tr></tr>"); }
newrows[i].append($(this));
});
});
$this.find("tr").remove();
$.each(newrows, function(){
$this.append(this);
});
});
return false;
});