Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML DOM Range deleteContents() Method

  • Last Updated : 08 Jul, 2020

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
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!