Remove cloned DIV by clicking button

Asked

Viewed 77 times

1

Some time ago I asked a question about how to clone a form DIV when clicking a button ( + )...

I got the following answer that helped me at the time.

REPLY

Now, I need to add a new button ( - ) so that when the user clicks, the cloned div is removed.

Current JS code:

Drawn up by: Sergio

function mais() {
    var destino = document.getElementById("aqui");
    var novadiv = document.createElement("div");
    var conteudo = document.getElementById("servico");
    novadiv.innerHTML = conteudo.innerHTML;
    destino.appendChild(novadiv);
}

I need help to implement a Function that does the following:

function menos(){
    //remove ultima div clonada...
}

jsFiddle: jsfiddle.net/qf2Lf914/

1 answer

2


thus?

function menos()
{
    var destino = document.getElementById("aqui");
    if (destino.lastChild)
    {
        destino.removeChild(destino.lastChild);
    }
}

http://jsfiddle.net/qf2Lf914/1/

  • Exactly what I needed, thank you very much!

Browser other questions tagged

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