Javascript Reference
Categories: Node

javascript Node insertBefore( )

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

insertBefore(newChildNode, referenceChildNodeOrNull)

  

Inserts a node as a child of the current node (usually the current node is an element) before one of the other child nodes of the current node. The new child can be a reference to an existing node in the document tree (in which case it is removed from its original position when this method is invoked). The child node may also be created anew as any valid DOM node type, including a document fragment (which may hold HTML tags) or Attr (the latter implemented for Netscape 6 and IE 6).

 

The second parameter allows you to specify a reference point among existing child nodes, in front of which the new child node is inserted. Alternatively, if you specify null as the second parameter (or omit the parameter in IE), the new node is inserted as the last child of the current nodethe same result as the appendChild( ) method.

 
Parameters
 
  • Any valid node object that can be a child of a parent node.
  • Any child node of the current node, or null.
 
Returned Value

Reference to the inserted node object.


Powered by Linode.