How to remove javascript cloned elements

0

How to remove only the last cloned node?

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>
    
asked by anonymous 05.08.2018 / 21:31

1 answer

1

Try this:

document.querySelector('#saida #linha:last-child').remove();
    
05.08.2018 / 21:40