Name
appendChild: newChild
Synopsis
Appends the newChild
node to the end of the child
list. If newChild
is already
linked into the document tree, it is unlinked before the append is
performed. This method returns a reference to the newChild
node.
Argument
- newChild: Node
The node to append. If the node is a
DocumentFragment
node, the children ofnewChild
are appended in sequence to the end of the node’s child list.
Exceptions
- HIERARCHY_REQUEST_ERR
Raised if the insert operation violates at least one document structure rule. For instance, the node doesn’t allow children or doesn’t allow children of the
newChild
node type. This exception is also raised if the operation creates a circular reference (i.e., it tries to insert a node’s parent as a node’s child).- WRONG_DOCUMENT_ERR
Raised if the
newChild
node is created in a different document than that of the new parent node.- NO_MODIFICATION_ALLOWED_ERR
Raised if the new parent node is read-only.
Java binding
public Node appendChild(Node newChild) throws DOMException;
Java example
// Move the first child to the end of the child node list if (elem.getFirstChild( ) != null) { elem.appendChild( elem.getFirstChild( ) ); }
Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.