Open In App

HTML DOM Range deleteContents() Method

Last Updated : 12 Jul, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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.

HTML




<!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:

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Safari 1
  • Opera 9
  • Internet Explorer 9

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads