views:

91

answers:

5

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 &amp;&amp; tbl.nodeName != 'TABLE') {
        tbl = tbl.parentNode;
      }

      if (tbl &amp;&amp; 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
This requires the jQuery library.
Fermin
yes this require j-query library i suggest this solution becuase its better to use for clean coding
Pranay Rana
now its for both jqery and javascript
Pranay Rana
+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
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
+2  A: 
var zTag = document.getElementById ('TableRowID');
zTag.parentNode.removeChild (zTag);

Or in jQuery:

$('#TableRowID').remove ();
Brock Adams
+3  A: 
var row = document.getElementById("row-id");
row.parentNode.removeChild(row);
Bobby Jack
+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
this also jquery solution not javascript
Pranay Rana