HTML DOM Range cloneContents() method

The cloneContents() returns a DocumentFragment object copying the Nodes and Contents included in the Range. All the range contents can be cloned to a DocumentFragment object.

cloneContents() method is similar to extractContents() method but extractContents() method copies the content to an object variable and removes the range content from DOM tree, whereas cloneContents() method copies the content to an object variable but do not removes the range content from DOM tree.


documentFragment = range.cloneContents();

Parameters: This method does not take any parameter.

Return value: This method returns a DocumentFragment object created from the contents of the Range.

Example: This example shows how to create a DocumentFragment object and append it to the document using this method.






<title>HTML DOM range cloneContents() method</title>   
<p>This is the Range Content</p>
    <button onclick="clone()">Click To Clone Contents</button>
    let range = document.createRange();
    let referenceNode = document.getElementsByTagName('p').item(0);
    function clone(){
        documentFragment = range.cloneContents();



Before Button Click:

After Button Click:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.