F
foldface
Hi
This works but is a bit long-winded. Is there a better way?
ta
F
<style>
..Header
{
background-color: gray;
}
</style>
<table id=theTable>
<tr>
<td class=Header nowrap style="bob: 1">Header1</td>
<td class=Header>Header2</td>
<td class=Header>Header3</td>
<td class=Header>Header4</td>
<td class=Header>Header5</td>
</tr>
<tr>
<td> Contents01 </td>
<td> Contents02 </td>
<td> Contents03 </td>
<td> Contents04 </td>
<td> Contents05 </td>
</tr>
<tr>
<td> Contents11 </td>
<td> Contents12 </td>
<td> Contents13 </td>
<td> Contents14 </td>
<td> Contents15 </td>
</tr>
</table>
<hr>
<input type=button value=PressMe onclick="func()">
<script>
function func()
{
var theTable = document.getElementById('theTable')
var theTable2 = document.createElement("table");
var numRows = theTable.rows.length;
var numCells = theTable.rows[0].cells.length;
for(var i=0; i<numCells; i++)
{
var newRow = theTable2.insertRow(-1)
for(var j=0; j<numRows; j++)
{
var cell = theTable.rows[j].cells;
var newCell = newRow.insertCell(-1);
newCell.innerHTML = cell.innerHTML;
newCell.className = cell.className;
newCell.style.cssText = cell.style.cssText
}
}
while (theTable.rows.length > 0)
{
theTable.deleteRow(0);
}
var numRows = theTable2.rows.length;
var numCells = theTable2.rows[0].cells.length;
debugger;
for(var i=0; i<numRows; i++)
{
var newRow = theTable.insertRow(-1)
for(var j=0; j<numCells; j++)
{
var cell = theTable2.rows.cells[j];
var newCell = newRow.insertCell(-1);
newCell.innerHTML = cell.innerHTML;
newCell.className = cell.className;
newCell.style.cssText = cell.style.cssText
}
}
while (theTable2.rows.length > 0)
{
theTable2.deleteRow(0);
}
}
</script>
This works but is a bit long-winded. Is there a better way?
ta
F
<style>
..Header
{
background-color: gray;
}
</style>
<table id=theTable>
<tr>
<td class=Header nowrap style="bob: 1">Header1</td>
<td class=Header>Header2</td>
<td class=Header>Header3</td>
<td class=Header>Header4</td>
<td class=Header>Header5</td>
</tr>
<tr>
<td> Contents01 </td>
<td> Contents02 </td>
<td> Contents03 </td>
<td> Contents04 </td>
<td> Contents05 </td>
</tr>
<tr>
<td> Contents11 </td>
<td> Contents12 </td>
<td> Contents13 </td>
<td> Contents14 </td>
<td> Contents15 </td>
</tr>
</table>
<hr>
<input type=button value=PressMe onclick="func()">
<script>
function func()
{
var theTable = document.getElementById('theTable')
var theTable2 = document.createElement("table");
var numRows = theTable.rows.length;
var numCells = theTable.rows[0].cells.length;
for(var i=0; i<numCells; i++)
{
var newRow = theTable2.insertRow(-1)
for(var j=0; j<numRows; j++)
{
var cell = theTable.rows[j].cells;
var newCell = newRow.insertCell(-1);
newCell.innerHTML = cell.innerHTML;
newCell.className = cell.className;
newCell.style.cssText = cell.style.cssText
}
}
while (theTable.rows.length > 0)
{
theTable.deleteRow(0);
}
var numRows = theTable2.rows.length;
var numCells = theTable2.rows[0].cells.length;
debugger;
for(var i=0; i<numRows; i++)
{
var newRow = theTable.insertRow(-1)
for(var j=0; j<numCells; j++)
{
var cell = theTable2.rows.cells[j];
var newCell = newRow.insertCell(-1);
newCell.innerHTML = cell.innerHTML;
newCell.className = cell.className;
newCell.style.cssText = cell.style.cssText
}
}
while (theTable2.rows.length > 0)
{
theTable2.deleteRow(0);
}
}
</script>