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

deleteContents method (Range)

Browser support:
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.


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:
    <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 ();
    <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>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content