--- title: Selection.deleteFromDocument() slug: Web/API/Selection/deleteFromDocument translation_of: Web/API/Selection/deleteFromDocument original_slug: Web/API/Selection/从Document中删除 ---
The Selection.deleteFromDocument()
method deletes the actual text being represented by a selection object from the document's DOM.
sel.deleteFromDocument()
None.
A user selects the (imaginary) text "ve two ea" from "Rabbits have two ears." on a web page. The user then clicks a button that executes the JavaScript snippet window.getSelection().deleteFromDocument()
. The document's text becomes "Rabbits hars."
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML Editing', '#dom-selection-deletefromdocument', 'Selection.deleteFromDocument()')}} | {{Spec2('HTML Editing')}} | Initial definition |
{{SpecName('Selection API', '#widl-Selection-deleteFromDocument-void', 'Selection.deleteFromDocument()')}} | {{Spec2('Selection API')}} | Current |