It is impossible with father.appendchild(son) because it is necessary that father be in the document before adding a child
That statement is not true.
You can start by checking documentation, and confirm that there is no mention of the statement you made.
However, we can put the appendChild
in code and see that it works by adding the node even when both are not in the DOM:
var pai = document.createElement('div');
var filho = document.createElement('div');
console.log(`Pai tem ${pai.childNodes.length} filhos`); //Pai tem 0 filhos
pai.appendChild(filho);
console.log(`Pai tem ${pai.childNodes.length} filhos`); //Pai tem 1 filhos
for (let i = 0; i < pai.childNodes.length; ++i){
console.log(`Filho ${i} é ${pai.childNodes[i].tagName}`);
}
Concluding:
It is indeed with the function appendChild
who adds children to us who are not yet in the GIFT.
serves
innerHTML
instead ofcreateElement
?– Costamilam
@Guilherme Costamilam, innerHTML will do, but I have doubts if it will work
– Raptador