I’m playing around with native javascript. I’m basically practicing basic node manipulations such — add, remove, move, copy, and create.
While testing move, I got a question.
if you look at the jsfiddle above, I’ve used “appendChild”. How come it moves a node to a new div? I know that I need to clone a node if I want to copy a node. It just doesn’t look/sound right with “appendChild” command.
Is this expected behavior?
A node can only have one parent. Therefore it moves it if you appends it to another node.
From documentation of appendChild:
From the same page:
Also note:
You can also read the w3c specification of appendChild: