In this specific case, the element is a table row.
+1
A:
Jquery
$('#myTableRow').remove();
This works fine if your row has an id
, such as:
<tr id="myTableRow"><td>blah</td></tr>
Pure Javascript :
Javascript Remove Row From Table
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 );
}
}
Pranay Rana
2010-07-14 09:10:34
This requires the jQuery library.
Fermin
2010-07-14 09:11:46
yes this require j-query library i suggest this solution becuase its better to use for clean coding
Pranay Rana
2010-07-14 09:13:32
now its for both jqery and javascript
Pranay Rana
2010-07-14 09:25:10
+6
A:
Untested but something like:
var tbl = document.getElementById('tableID');
var row = document.getElementById('rowID');
tbl.removeChild(row);
or
var row = document.getElementById('rowID');
row.parentNode.removeChild(row);
Fermin
2010-07-14 09:11:23
You don't need a hardcoded reference to the parent.. you can get it from the row itself.. `row.parentNode.removeChild(row);` This way you only need the id of the element you want to remove ..
Gaby
2010-07-14 09:15:37
+2
A:
var zTag = document.getElementById ('TableRowID');
zTag.parentNode.removeChild (zTag);
Or in jQuery:
$('#TableRowID').remove ();
Brock Adams
2010-07-14 09:12:49
+3
A:
var row = document.getElementById("row-id");
row.parentNode.removeChild(row);
Bobby Jack
2010-07-14 09:13:16
+1
A:
check this stackoverflow query http://stackoverflow.com/questions/170997/what-is-the-best-way-to-remove-a-table-row-with-jquery
Jaison Justus
2010-07-14 09:13:23