How to remove javascript cloned elements

Asked

Viewed 89 times

0

How to remove only the last cloned Ode?

document.getElementById("add").onclick = function clonar() {
var linha = document.getElementById("linha");
var clone = linha.cloneNode(true);
document.getElementById("saida").appendChild(clone);  
}
button {width:50px}
.quadrado {
background:black;
height:50px;
width:50px;
margin-bottom:3px;
}
<div id="linha"><div class="quadrado"></div></div>
<div id="saida"></div>
<button id="add">ADD</button><br>
<button id="del">DEL</button>

1 answer

1


Try this:

document.querySelector('#saida #linha:last-child').remove();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.