Javascript Remove Row From Table
Posted by admin on
May 20, 2008
Here’s a short function to remove a row from a table using the row’s id
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 ); } }







10 Responses to “Javascript Remove Row From Table”
Very Good! Many Thanks!!! Bye
By Diego on Mar 20, 2009
my pleasure dude
By tech on Apr 27, 2009
How bout pairing this script with one that ads a row instead of deleting?
By Dexter on Dec 17, 2009
i will have to look the code for that one.
By tech on Dec 17, 2009
This is perfect! Thanks for the clear article!
By Klom Dark on Feb 18, 2010
you’re welcome
By tech on Feb 18, 2010
This is a very exciting post, I was looking for this information. Just so you know I found your site when I was doing research for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.
By Markita Palmerino on Apr 11, 2010
Thanks for this awesome source!
By Edward Aum on Aug 13, 2010
@edward: you’re welcome
By tech on Aug 13, 2010
Awesome
Works lik magic!
Was looking for something lik this
By Shruti on Sep 2, 2011