HTML JS

REMOVE TABLE ROWS & CELLS

(quick guide & examples)

<table id="demo">   <tr><td>A</td> <td>B</td></tr>   <tr><td>C</td> <td>D</td></tr> </table>

GET TABLE var table = document.getElementById("demo");

REMOVE ROW & CELL

01

REMOVE SECOND ROW table.deleteRow(1);

REMOVE FIRST CELL OF FIRST ROW var firstRow = table.rows[0]; firstRow.deleteCell(0);

<table>   <tr id="rowA">     <td>A</td> <td>B</td> <td>C</td>  </tr>   <tr>     <td class="cellB">D</td> <td>E</td>     <td class="cellB">F</td>   </tr> </table>

REMOVE #ROWA document.getElementById("rowA") .remove();

ALTERNATIVE METHOD

02

REMOVE ALL CELLS WITH .CELLB for (let c of document.querySelectorAll ("#demoC td.cellC")) { c.remove(); }