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

deleteContents method (Range)

Browser support:
9
Deletes the contents of the current Range from the document tree.
Note: The Range object and its deleteContents method are supported in Internet Explorer from version 9.
If you need the removed content for later use, delete the contents with the extractContents method.

Syntax:

object.deleteContents ( );
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 illustrates the use of the deleteContents method:
<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 ();
            }
        }
    </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