Javascript Reference
Categories: Node

javascript Node appendChild( )

@March 15, 2008, 1:22 a.m.
appendChild( )Firefox/Netscape/NN 6 IE 5 Chrome/Safari/DOM 1  

appendChild(nodeObject)

  

Inserts a new node after the end of the last child node of the current node object. The current node object must be capable of containing child nodes, otherwise the method throws an exception. This method is the most common way to append a dynamically created element, text node, or document fragment to an existing element, such as a script might do when assembling a chunk of new content for a document. But if the node reference passed as a parameter with the appendChild( ) method points to an existing node in the document tree, that node is first removed from the tree, and then appended to the end of the list of child nodes in the current object. This provides a shortcut way to move a node from one location to the end of a container.

 

Appending one text node as a sibling to an existing text node does not join the two text nodes together. To combine all sibling text nodes into one large text node, invoke the parent's normalize( ) method.

 
Parameters
 
  • Reference to any node object of a type that makes sense to become a child of the current object. It may be from dynamically-generated content (e.g., text node, element, or document fragment) or a node from the existing document tree.
 
Returned Value

Reference to the appended node.

|
Spears wjmz - 2013-09-12
|
Bernard hx - 2013-09-05
|
Kübler-Ross tm - 2013-08-20

Powered by Linode.