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

detach method (Range)

Browser support:
9
Releases the current Range object and allows the browser to free up resources.
Note: The Range object and its detach method are supported in Internet Explorer from version 9.
Detached Range objects cannot be used later. When you work several Range objects simultaneously, the use of the detach method is preferred to improve performance.

Syntax:

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

Return value:

This method has no return value.

Example HTML code 1:

This example shows how to detach a Range after it is not needed any more:
<head>
    <script type="text/javascript">
        function RemoveContent () {
            var srcObj = document.getElementById ("src");

            if (document.createRange) {     // all browsers, except IE before version 9
                var rangeObj = document.createRange ();
                rangeObj.selectNodeContents (srcObj);
                rangeObj.deleteContents ();

                    // rangeObj is already not needed
                rangeObj.detach ();

                    // ...
            }
        }
    </script>
</head>
<body>
    <div id="src" style="background-color:#e0a0b0; width:300px; height:50px;">The <b>contents</b> of the <i>source</i> element.</div>
    <br /><br />
    <button onclick="RemoveContent ();">Remove the contents of the source element!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content