deleteFromDocument method

Deletes the selected nodes from a document.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 7.6.1Internet Explorer 9



HRESULT retVal = object.deleteFromDocument();


This method has no parameters.

Return value


If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information


In the following example, select the text and elements in the shaded section. When the mouse button is released, the selected items are deleted. Refresh the page to try again.

<!DOCTYPE html>
    <title>Delete From Document</title>        
        <script type="text/javascript">
        function deleteSelectedContent() {
        if (window.getSelection){                       //check for a selection
            var selection = window.getSelection();      //get a selection object
            selection.deleteFromDocument();             //remove content            
        function refresh()                 
          window.location.reload( false );              //reload our page
    <div onmouseup="deleteSelectedContent ()" style="background-color:#c0c0c0;"  >
<h1>Now you see it</h1>
<p>Select some text or elements on this page. When you release the mouse button, it will be gone. </p>
<h2>h2 header</h2>
<p>Some more sample text to <strong>delete</strong>.</p>
 <input type="button" value="Refresh page" onclick="refresh()"   />