XML DOM insertBefore() Method
Complete Element Object Reference
Definition and Usage
The insertBefore() method inserts a new child node before an existing child
node.
This method returns the new child node.
Syntax
|
elementNode.insertBefore(new_node,existing_node)
|
| Parameter |
Description |
| new_node |
Required. The node to insert |
| existing_node |
Required. The existing node. The new node is inserted before this node. |
Example
The following code fragment loads "books.xml"
into xmlDoc using
loadXMLDoc(), creates a new <book> node and inserts it before
the last <book>
element:
Example
xmlDoc=loadXMLDoc("books.xml");
newNode=xmlDoc.createElement("book");
x=xmlDoc.documentElement;
y=xmlDoc.getElementsByTagName("book")[3];
x.insertBefore(newNode,y);
|
Try it yourself »
|
Complete Element Object Reference

The Altova MissionKit is an integrated suite of tools ideal for:
- XML development
- Web & Web services development
- Data mapping & integration
- Rendering & publishing XML & database data
- XBRL validation, taxonomy editing, transformation & rendering
The MissionKit for XML Developers includes XMLSpy® - the industry-leading XML editor; MapForce® - a
graphical data mapping, conversion, and integration tool; StyleVision® - a visual XSLT stylesheet designer;
DiffDog® - an XML-aware diff/merge tool; and 2 additional tools.
Try all 6 products free for 30 days!
Download a fully-functional free trial
|
|
|
|