Web APIs

Document.createDocumentFragment()

Try the free JavaScript compiler

A DocumentFragment is a container for nodes outside the document tree. Inserting the fragment moves its children into the destination, leaving the fragment empty. It is useful for organizing construction, not a universal performance guarantee.

Formal Syntax & Structure

javascript syntaxjavascript
document.createDocumentFragment()

Return Value

DocumentFragment

New empty fragment.

Working Example

Example Snippetjavascript
const f=document.createDocumentFragment();f.append(document.createElement("li"),document.createElement("li"));const ul=document.createElement("ul");ul.append(f);console.log(f.childNodes.length,ul.children.length);
JavaScript Reference