You are here: Reference > JavaScript > client-side > selection and ranges > methods > duplicate (TextRange)

duplicate method (TextRange)

Browser support:
Returns an exact copy of the current TextRange object.
Similarly, use the cloneRange method to clone a Range in other browsers.


object.duplicate ( );
You can find the related objects in the Supported by objects section below.

Return value:

Returns the newly created TextRange object.

Example HTML code 1:

This example illustrates the use of the duplicate method:
    <script type="text/javascript">
        function CloneARange () {  // Internet Explorer
            if (document.createRange) {     // all browsers, except IE before version 9
                var rangeObj = document.createRange ();
                rangeObj.selectNodeContents (document.body);
                var rangeClone = rangeObj.cloneRange ();
                alert (rangeClone.toString ());
            else {  // Internet Explorer before version 9
                if (document.body.createTextRange) {
                    var rangeObj = self.document.body.createTextRange ();
                    var rangeClone = rangeObj.duplicate ();
                    alert (rangeClone.htmlText);
    <button onclick="CloneARange ();">Clone a range!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content