From what I understand you just want to know how to delete any element of the DOM.
Well, being elemento
the element you want to remove, it is possible to do the following
elemento.parentNode.removeChild(elemento);
Take an example:
document.getElementById('bt').addEventListener('click', function() {
const id = document.getElementById('txtrem').value;
const el = document.getElementById(id);
el.parentNode.removeChild(el);
});
<table id="tblItens" width="400px">
<tr>
<td id="td1">1</td>
<td id="td1">2</td>
<td id="td1">3</td>
</tr>
</table>
<label>Digite o Id que deseja remover</label><br>
<input type="text" id="txtrem">
<button id="bt"> teste </button>
You want to remove the contents of the <td> from the iteration of a button, a click? would explain better , or to which the example applies?
– Felipe
Yes, through an onclick of the button
– Sora
There are 3 tds. Which td you want to remove?
– Sam
I wonder what are the ways to remove the content of both a td and all
– Sora
@Sora Please be a little more specific. You need to remove a
td
within atr
, right? But what is the criterion for this? Or do you just want to know which function you can use to remove it?– Jéf Bueno
I would like to know only which function can remove both an element and all elements of
tds
within this table @LINQ– Sora