AvailabilityDOM Level 1 Core SynopsisNode appendChild(Node newChild) throws DOMException; Arguments
ReturnsThe node that was added. ThrowsThis method may throw a DOMException with one of the following code values in the following circumstances:
DescriptionThis method adds the node newChild to the document, inserting it as the last child of this node. If newChild is already in the document tree, it is removed from the tree and then reinserted at its new location. If newChild is a DocumentFragment node, it is not inserted itself; instead, all its children are appended, in order, to the end of this node's childNodes[] array. Note that a node from (or created by) one document cannot be inserted into a different document. That is, the ownerDocument property of newChild must be the same as the ownerDocument property of this node. ExampleThe following function inserts a new paragraph at the end of the document: function appendMessage(message) { var pElement = document.createElement("P"); var messageNode = document.createTextNode(message); pElement.appendChild(messageNode); // Add text to paragraph document.body.appendChild(pElement); // Add paragraph to document body } See AlsoNode.insertBefore( ), Node.removeChild( ), Node.replaceChild( ) |