DOM Document.createDocumentFragment() Method
The createDocumentFragment() method creates an empty DocumentFragment, an off-screen container for building groups of elements.
Description
The createDocumentFragment() method returns a new, empty DocumentFragment. Build a set of elements inside it, then insert the fragment in one step; its children move into the page and the fragment becomes empty. new DocumentFragment() does the same.
Modern browsers already batch DOM updates, so fragments matter less for performance than they once did, but they're still a clear way to assemble a group of elements before adding them in one place. Methods such as append() also accept several nodes at once, which can make a fragment unnecessary for small groups.
A fragment can be appended only once usefully, since its children move out when it's inserted. To insert the same content in several places, clone the fragment with cloneNode(true) for each one.
Syntax
document.createDocumentFragment()Return Value
A new, empty DocumentFragment.
Example
Browser Support
The following information will show you the current browser support for the Document.createDocumentFragment() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





