The createDocumentFragment() method in HTML DOM is used to create the document fragment which is useful to change the content of the document such as delete, modify or add a new node. This method creates the document fragment, then append the elements of the document to the document fragment and make the changes according to the need. Finally, append the document fragment to the document. It is a safe method and thus prevents destroying of the DOM structure.
Parameters: This method does not accepts any parameter.
Return Value: It returns the created DocumentFragment node.
Before click on the button:
After click on the button:
Supported Browsers: The browser supported by DOM createDocumentFragment() Method are listed below:
- Google Chrome
- Internet Explorer