Is there an opposite of .cloneNode?

Viewed 24

I am writing a recipe website submit form and in the form I increase the amount of ingredients with this code.

addIngredientsBtn.addEventListener('click', function(){
    let newIngredients = ingredientDiv.cloneNode(true);
    let input = newIngredients.getElementsByTagName('input')[0];
    input.value = '';
    ingredientList.appendChild(newIngredients);
}); 

how do I reverse this to remove nodes from the form? Thanks for any help

1 Answers

As you add each node you can do something like this:

newIngredients.addEventListener('click', function(){
   this.parentNode.removeChild(this);
});
Related