--- title: Selection.deleteFromDocument() slug: Web/API/Selection/从Document中删除 translation_of: Web/API/Selection/deleteFromDocument ---
{{ ApiRef("DOM") }}{{SeeCompatTable}}

The Selection.deleteFromDocument() method deletes the actual text being represented by a selection object from the document's DOM.

Syntax

sel.deleteFromDocument()

Parameters

None.

Examples

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."

Specifications

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

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatUnknown}} {{CompatVersionUnknown()}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatVersionUnknown()}} 1.0 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

See also