-3
I have a table and I want to delete her lines, but I also want to prevent the first line from being deleted, I was able to make the code but it excludes besides the other lines, the first also
js code
const btnAdd = document.querySelector('a.add').addEventListener('click', function(){
var table = document.getElementById('tabela')
var row = table.insertRow(2)
row.insertCell(0).innerHTML = `<input type="text" name="r1[]" id='desc' placeholder="Descrição">`
row.insertCell(1).innerHTML = `<input type="text" name="r2[]" id='valor' placeholder="Valor">`
row.insertCell(2).innerHTML = `<input type="text" name="r3[]" id='quantidade' placeholder="Quantidade">`
row.insertCell(3).innerHTML = `<a href="#" class="remover" onclick="removerLinha()">Remover Campo</a>`
})
function removerLinha(){
var result = document.getElementById('desc', 'valor', 'quantidade')
result.parentNode.parentNode.remove()
}
HTML
<!DOCTYPE html>
<html>
<head>
<title>Área Restrita</title>
<meta charset="utf-8">
</head>
<body>
<h1>Olá, <?php echo $dados['nome']; ?></h1>
<a href="../controller/logout.php">Sair</a>
<form action="../controller/salvaRegistro.php" method="POST">
<table id="tabela">
<thead>
<tr>
<th>Descrição</th>
<th>Valor Unitário</th>
<th>Quantidade</th>
</tr>
</thead>
<tbody>
<tr id="s">
<td><input type="text" name="r1[]" id="desc" placeholder="Descrição"></td>
<td><input type="text" name="r2[]" id="valor" placeholder="Valor"></td>
<td><input type="text" name="r3[]" id="quantidade" placeholder="Quantidade"></td>
<a href="#" class="remover" onclick="removerLinha()" hidden>Remover Campo</a>
<a href="#" class="add">adicionar campo</a>
</tr>
</tbody>
</table>
<input id="enviar" type="submit" value="salvar">
</form>
<script src="main.js"></script>
</body>
</html>
just so just change the HTML compos ids
– user60252