If the current node is an attribute, 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_COMMENT, NODE_DOCUMENT, NODE_DOCUMENT_TYPE, NODE_ELEMENT, NODE_ENTITY, NODE_NOTATION, NODE_PROCESSING_INSTRUCTION |
Returns an error. These node types cannot be children of an attribute. |
NODE_DOCUMENT_FRAGMENT |
Inserts the children of the document fragment (newChild) and returns newChild. |
NODE_ENTITY_REFERENCE, NODE_TEXT |
Inserts newChild and returns newChild. |
NODE_CDATA_SECTION, NODE_COMMENT, NODE_ENTITY, NODE_NOTATION, NODE_PROCESSING_INSTRUCTION, NODE_TEXT |
Returns an error. These node types either cannot have children or their children are read-only. |
If the current node is a document, calling insertBefore has the following results, depending on the value of the newChild parameter.
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. |
If the current node is a document fragment, calling insertBefore has the following results, depending on the value of the newChild parameter.
NODE_ATTRIBUTE, NODE_DOCUMENT, NODE_DOCUMENT_TYPE |
Returns an error. These nodes types are not valid as children of a document fragment. |
NODE_CDATA_SECTION, NODE_COMMENT, NODE_ELEMENT, NODE_ENTITY_REFERENCE, NODE_PROCESSING_INSTRUCTION, NODE_TEXT |
Inserts newChild and returns newChild. |
NODE_DOCUMENT_FRAGMENT |
Inserts the children of the document fragment (newChild) and returns newChild. |
NODE_ENTITY, NODE_NOTATION |
Returns an error. Entities and notations are read-only and cannot be inserted into a document. |
If the current node is an element, calling insertBefore has the following results, depending on the value of the newChild parameter.
NODE_CDATA_SECTION, NODE_COMMENT, NODE_ELEMENT, NODE_ENTITY_REFERENCE, NODE_TEXT, NODE_PROCESSING_INSTRUCTION |
Inserts newChild and returns newChild. |
NODE_ATTRIBUTE, NODE_DOCUMENT, NODE_DOCUMENT_TYPE, NODE_ENTITY, NODE_NOTATION |
Returns an error. These node types cannot be children of an element node. |
NODE_DOCUMENT_FRAGMENT |
Inserts the children of the document fragment (newChild) and returns newChild. |
NODE_ENTITY_REFERENCE |
Returns an error. Although the child nodes of an entity reference are the expanded entity, the children cannot be modified. |