Just trying to remove a table but loop is not removing all rows. I have used alert to be sure it's the right element by id. It does remove some rows but not all, just chunks. console reports: DOM Exception 1,DOM Exception 8
function removeThis(unsetE开发者_C百科lement)
{ unsetElement.parentNode.removeChild(unsetElement); }
While you remove rows, their indices change; you need to do the loop from the top, i.e.
i=rowCounter-1;
while(i>=0){unsetTable.deleteRow(i);i--;}
Yet the better idea is just to purge the whole table; rows will be garbage-collected.
Another solution could be to use the special -1
index, which deletes the last row.
var i = thisTrAry.length;
while(i--) {
unsetTable.deleteRow(-1);
}
But if you remove the whole table anyway (in your last line) then there is no need to remove the rows first.
精彩评论