The documentFragment type is a small document which contains nodes to be added or manipulated. The nodes can be added to awebpage without rendering the whole document. The documentFragment type acts as a repository for manipulated or new nodes to be added to the document and is not displayed as a markup.

The documentFragment type characteristics are:

The document fragments are created by using document.createFragment() object. The object inherits its properties from the Node and has all methods of the Node. After applying the createFragment() method, node to be added to document will be added to it. With the insertBefore() or appendChild() methods, the node is moved without adding the whole documentFragment to the document. Similarly when removing a node form document, only the node gets removed and added to document Fragment without rendering whole document.

Example of changing an element in a list by using documentFragment

 

›› go to examples ››