Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

HTML | DOM createDocumentFragment() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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. 



<!DOCTYPE html>
    <!--script to delete first child of
    the list, and modify it -->
        function myGeeks() {
            var doc = document.createDocumentFragment();
            doc.childNodes[0].childNodes[0].nodeValue =
        DOM createDocumentFragment() Method
        Click on the button to change
        list element
        <li>Data Structure</li>
        <li>Operating System</li>
        <li>C Programming</li>
    <button onclick = "myGeeks()">
        Click Here!


Before click on the button:


After click on the button:


Supported Browsers: The browser supported by DOM createDocumentFragment() Method are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 6 and above
  • Firefox 1 and above
  • Opera 12.1 and above
  • Safari 1 and above

My Personal Notes arrow_drop_up
Last Updated : 11 Jul, 2022
Like Article
Save Article
Similar Reads
Related Tutorials