Hello, I am trying to completely remove everything from a table. I want to delete all of the rows which I am able to do. But when I delete all of the rows and add rows in again there is whitespace at the top of the table and I can't figure out why it is there. Here is my code:
<html>
<head>
<style type="text/css">
td {
font-size: 200%;
}
</style>
<script type="text/javascript">
function removeTables()
{
var table = document.getElementById("myTable");
for(var i = table.rows.length - 1; i >= 0; i--) {
table.deleteRow(i);
}
document.getElementById("myTable").innerHTML = "";
}
function addTables()
{
for(var i = 5; i >= 0; i--) {
var row = document.createElement('tr');
var cell1 = document.createElement('td');
var cell2 = document.createElement('td');
cell1.innerHTML = i + " Left";
cell2.innerHTML = i + " Right";
row.appendChild(cell1);
row.appendChild(cell2);
document.getElementById('myTable').appendChild(row);
}
}
</script>
</head>
<body>
<table id="myTable" cellpadding="8" cellspacing="8" border="2">
</table>
<button onclick="removeTables();">Remove Elements</button>
<button onclick="addTables();">Add Elements</button>
</body>
</html>
After I do an add elements, delete elements, and add elements again, there is whitespace at the top of the table. Repeat the process several times and the whitespace adds up. How do I remove this whitespace?