Here’s a short function to remove a row from a table using the row’s id
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
function removeRow(id) { var tr = document.getElementById(id); if (tr) { if (tr.nodeName == 'TR') { var tbl = tr; // Look up the hierarchy for TABLE while (tbl != document && tbl.nodeName != 'TABLE') { tbl = tbl.parentNode; } if (tbl && tbl.nodeName == 'TABLE') { while (tr.hasChildNodes()) { tr.removeChild( tr.lastChild ); } tr.parentNode.removeChild( tr ); } } else { alert( 'Specified document element is not a TR. id=' + id ); } } else { alert( 'Specified document element is not found. id=' + id ); } } |