Create a documentFragment node,
append a child to it
(a list item),
change the list item's node value,
insert it
as the last child of the list:
The result will be:
Before the changes:
After the changes:
The createDocumentFragment() method creates a imaginary Node object, with all the properties and methods of the Node object.
The createDocumentFragment() method is usefull when you want to extract parts of your document, change, add, or delete, some of the content, and insert it back to your document.
You can also use the document's Document object to perform these changes, but to prevent destroying the document structure, it can be safer to extraxt only parts of the document, make the changes, and insert the part back to the document.
Note: Nodes being appended to the document fragment, from the document, will be removed from the document.
![]()
The createDocumentFragment() method is supported in all major browsers.
None.
| Type | Description |
|---|---|
| DocumentFragment object | The created DocumentFragment node |
| DOM Version | Core Level 1 |
|---|
Your message has been sent to W3Schools.