Section 25.210. Node.appendChild( ): insert a node as the last child of this node


25.210. Node.appendChild( ): insert a node as the last child of this node

DOM Level 1 Core

25.210.1. Synopsis

 Node appendChild(Node newChild)     tHRows DOMException; 

25.210.1.1. Arguments

newChild

The node to be inserted into the document. If the node is a DocumentFragment, it is not directly inserted, but each of its children are.

25.210.1.2. Returns

The node that was added.

25.210.1.3. Throws

This method may throw a DOMException with one of the following code values in the following circumstances:


HIERARCHY_REQUEST_ERR

The node does not allow children, it does not allow children of the specified type, or newChild is an ancestor of this node (or is this node itself).


WRONG_DOCUMENT_ERR

The ownerDocument property of newChild is not the same as the ownerDocument property of this node.


NO_MODIFICATION_ALLOWED_ERR

This node is read-only and does not allow children to be appended, or the node being appended is already part of the document tree, and its parent is read-only and does not allow children to be removed.

25.210.2. Description

This 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.

25.210.3. Example

The 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 } 

25.210.4. See Also

Node.insertBefore( ), Node.removeChild( ), Node.replaceChild( )




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net