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 newChild | Result |
---|---|
NODE_ATTRIBUTE , NODE_CDATA_SECTION , NODE_DOCUMENT , NODE_ENTITY , NODE_ENTITY_REFERENCE , NODE_NOTATION, NODE_TEXT |
Returns an error. These nodes are not valid as children of a document node. |
NODE_COMMENT , NODE_PROCESSING_INSTRUCTION |
Inserts newChild and returns newChild . |
NODE_ELEMENT |
Inserts 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_FRAGMENT |
Inserts 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_TYPE |
Returns an error. The document type is read-only. |