Calling insertBefore on Documents


If the current node is a document, calling insertBefore has the following results, depending on the value of the newChild parameter.

Node type passed in newChildResult
NODE_ATTRIBUTE, NODE_CDATA_SECTION, NODE_DOCUMENT, NODE_ENTITY, NODE_ENTITY_REFERENCE, NODE_NOTATION, NODE_TEXTReturns an error. These nodes are not valid as children of a document node.
NODE_COMMENT, NODE_PROCESSING_INSTRUCTIONInserts newChild and returns newChild.
NODE_ELEMENTInserts newChild and returns newChild. By definition, an XML document (the Document node) can have only a single child. Therefore, an error is returned if the Document node already has a child.
NODE_DOCUMENT_FRAGMENTInserts the children of the document fragment (in newChild) and returns newChild. The insert operations are subject to the rules for child nodes and can fail if the document fragment children represent node types that cannot be inserted.
NODE_DOCUMENT_TYPEReturns an error. The document type is read-only.