Java script to remove html tags TR

Hi Guys,

I’m new at JS.
I need to remove TR elements from parent table but the problem is there are no table ID/Name

Is it possible to perform it?
Please see attach - i need remove red marked block… what scrip i have to use if i will put it to the green block?
Thank you.

A simpler version of the same script:

function remove_rows(el) {
    var row = el.parentNode.parentNode;
    row.parentNode.removeChild(row);
}

(BTW, TriLLi, your table variable is slightly misnamed. It should be called tbody (unless you are using XHTML served as an application of XML).)

hi,

yes you can remove all tr-s from parent table, for example if you have structure like this


<table>
  <tr>
      <td><a href="#" onclick="remove_rows(this); return false;">remove all rows</a>
      </td>
   </tr>
  <tr>
      <td><a href="#" onclick="remove_rows(this); return false;">remove all rows</a>
      </td>
   </tr>
  <tr>
      <td><a href="#" onclick="remove_rows(this); return false;">remove all rows</a>
      </td>
   </tr>
  <tr>
      <td><a href="#" onclick="remove_rows(this); return false;">remove all rows</a>
      </td>
   </tr>
  <tr>
      <td><a href="#" onclick="remove_rows(this); return false;">remove all rows</a>
      </td>
   </tr>
  <tr>
      <td><a href="#" onclick="remove_rows(this); return false;">remove all rows</a>
      </td>
   </tr>
  <tr>
      <td><a href="#" onclick="remove_rows(this); return false;">remove all rows</a>
      </td>
   </tr>
</table>

then you can remove them like this


function remove_rows(el)
{
 var table = el.parentNode.parentNode.parentNode;
 var rows = table.rows.length;
 for(var i = rows-1; i > = 0; i--)
 {
    table.deleteRow(i);
 }
}

I hope that this is what you are looking for