Appendchild and removechild If the parent nodes of the nodes to be operated are both body, then there is no need to obtain the body parent node in advance. Or if the parent node is not the body, it is necessary to obtain the parent node in advance before using it?
Similar to this
There is no such usage
As for what you said, there is no need to obtain and operate the parent node of the body. The code does not know where to operate, and an error will definitely be reported.
Node.removeChild() method removes a child node from the DOM. Return deleted nodes.
Grammar
child is the child node to be removed.
node is the parent node of child.
oldChild holds a reference to the deleted child node. oldChild === child.
It is recommended that you read: https://developer.mozilla.org...
The
Node.appendChild() method adds a node to the end of the child node list of the specified parent node.
node is the parent node to insert the child node.
child is both the parameter and the return value of this method.
Example:
It is recommended that you read: https://developer.mozilla.org...
Be sure to get the parent element first before using appendChild(), otherwise how can you be sure it is added after that element. . . . . .
The<body> tag also has parent nodes and sibling nodes of <head><html>, so it’s best to get the parent node
The parent node must be obtained in advance. The case is to use document.body directly. Get the parent node body. This is a specification established by DOM level 0. If the parent node is not body. Get it separately. Because other parent nodes are different from body.