Skip to content
Related Articles

Related Articles

HTML DOM Range extractContents() Method

Improve Article
Save Article
Like Article
  • Last Updated : 08 Jul, 2020

The extractContents() method moves the contents of the Range from the document tree into a document object variable. The contents of the Range gets removed from the document tree.

The extractContents() method is similar to the cloneContents() method. The extractContents() method creates a DocumentFragment object from the contents of a Range object and it removes the contents of the Range from the document tree.


documentFragment = range.extractContents();

Parameters: This method does not accept any parameters.

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 an element using this method.


<!DOCTYPE html>
        HTML DOM range extractContents() method
    <p>RANGE CONTENT</p>
    <button onclick="extract()">
        Click to Extract the Range
    <h1 id="element">
        Below is extracted range: 
        var range = document.createRange();
        const element = 
        function extract() {
            var documentFragment = 


  • Before Click the Button:

  • After Click the Button:

Supported Browsers:

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!