Open In App

HTML DOM Range deleteContents() Method

The deleteContents() method deletes all the contents of the Range from the Document tree.

Syntax:



range.deleteContents()

Parameters: This method does not accept any parameters.

Return value: This method does not return any value.



Example: This example describes how to delete the current range from the document tree.




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM range deleteContents() method
    </title>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
 
     
<p>This is the range content.</p>
 
 
    <button onclick="del()">
        Click to delete
    </button>
 
    <script>
        var range = document.createRange();
        range.selectNode(document
            .getElementsByTagName("p").item(0));
             
        function del() {
            range.deleteContents();
        }
    </script>
</body>
 
</html>

Output:

Before Click the Button:
 

After Click the Button:

Supported Browsers:

Article Tags :