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
<!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
Last Updated :
12 Jul, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...