HTML DOM createDocumentFragment()
Method
Example
Creating a documentFragment node:
Output result:
Before modification:
Coffee
Tea
After modification:
Tea
Milk
Definition and Usage
The createDocumentFragment()
method creates a virtual node object that contains all properties and methods.
When you want to extract a part of the document, make changes, add, or remove content, and insert it at the end of the document, you can use the createDocumentFragment()
method.
You can also use the document's document object to perform these changes, but to prevent the document structure from being damaged, the createDocumentFragment()
method allows for safer modification of the document's structure and nodes.
Browser Support
All major browsers support the createDocumentFragment()
method.
Syntax
Parameters
None.
Return Value
Type | Description |
---|---|
DocumentFragment Object | Creates a document fragment object |
Technical Details
| DOM Version | Core Level 1 Document Object | | --- | --- |