O
O
olya_0972018-03-04 12:33:31
JavaScript
olya_097, 2018-03-04 12:33:31

The last line is not clear, what does this mean, besides the fact that we are making a copy, why write input.parentElement.appendChild(clone);?

<input type="submit" id="button">
<input type="text" id="input">
var input = document.getElementById('input');
var button = document.getElementById('button');

button.addEventListener('click', func);

function func(){
  var clone = input.cloneNode(true);
  input.parentElement.appendChild(clone);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2018-03-04
@SagePtr

var clone = input.cloneNode(true); - this is we create a copy of the element in memory
input.parentElement.appendChild(clone); - this is we add our copy to the DOM tree as a child node of the parent element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question