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.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

  • Before Click the Button:
     

  • After Click the Button:

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.