You want to change the HTML like this:
<tr><td>A</td><td>B</td><td>C</td><td>D</td></tr> <tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>
In it:
<tr><td>A</td><td>1</td></tr> <tr><td>B</td><td>2</td></tr> <tr><td>C</td><td>3</td></tr> <tr><td>D</td><td>4</td></tr>
Correctly?
You can do this using Javascript, however it is difficult to suggest a method without knowing more about the structure of your site / HTML files. I will give it back.
Assuming the <table> has an identifier (for example: <table id="myTable"> ), you can access it in javascript as follows:
var myTable = document.getElementById('myTable');
You can create a new table as follows:
var newTable = document.createElement('table');
Now you need to move the old tables to the new table columns:
var maxColumns = 0; // Find the max number of columns for(var r = 0; r < myTable.rows.length; r++) { if(myTable.rows[r].cells.length > maxColumns) { maxColumns = myTable.rows[r].cells.length; } } for(var c = 0; c < maxColumns; c++) { newTable.insertRow(c); for(var r = 0; r < myTable.rows.length; r++) { if(myTable.rows[r].length <= c) { newTable.rows[c].insertCell(r); newTable.rows[c].cells[r] = '-'; } else { newTable.rows[c].insertCell(r); newTable.rows[c].cells[r] = myTable.rows[r].cells[c].innerHTML; } } }
This should do what you need. Be warned: not verified. Working with this javascript code on an HTML page is left as an exercise for the reader. If someone sees errors that I missed, I will be satisfied if you point them to me or just edit to fix :)
Daniel Bingham
source share