Share via


Calling insertBefore on Document Fragments

 

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

Node type passed in newChild Result
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.

Remarks

If newChild is a node of type DOCUMENT_FRAGMENT, all its children are inserted, in the same order, before refChild.

If an entity reference is added as a child to a document fragment, the namespace declaration of the entity reference is added to the containing element.