HTML DOM Range cloneRange() Method

The cloneRange() method is used to make a clone of original range and returns that cloned Range object it into a new variable.

Note: Change in either Range does not affect the other Range.

Syntax:

newRange = originalRange.cloneRange();

Parameters: This method does not accept any parameter.

Return Value: This method returns the newly created range object.



Example: In this example, a range is cloned. For more clarification of cloned range, a cloned range is converted into string text using toString() method and showed that cloned range object in the console.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM range cloneRange() method
    </title>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <p>This is the range.</p>
  
    <script>
        originalRange = document.createRange();
          
        originalRange.selectNode(document
            .getElementsByTagName("p").item(0));
              
        clonedRange = originalRange.cloneRange();
        console.log(clonedRange);
        console.log(clonedRange.toString());
    </script>
</body>
  
</html>

chevron_right


Output: In console, the new cloned range object can be seen.

Supported Browsers: 

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera

full-stack-img

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 contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.