This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

extractContents

Summary

Removes the contents of a range from a document or document fragment and puts it a new document fragment.

Method of dom/Rangedom/Range

Syntax

var documentFragment = range.extractContents(/* see parameter list */);

Parameters

oDocumentFragment

Data-type
any

Returns an object that contains the extracted content.

Return Value

Returns an object of type DOM NodeDOM Node

Type: HRESULT

This method can return one of these values.

Return codeDescription
S_OKThe operation completed successfully.
InvalidStateErrordetach has been invoked on the object.
W3Exception_DOM_HIERARCHY_REQUEST_ERRA document type node is included in the range that is being cloned.
W3Exception_DOM_NO_MODIFICATION_ALLOWED_ERRA node or portion of the content in the range is read-only.

Examples

range = document.createRange();
range.selectNode(document.getElementsByTagName("div").item(0));
documentFragment = range.extractContents();
document.body.appendChild(documentFragment);

Notes

Event Listeners added using DOM Events are not retained during extraction. HTML attribute events are retained or duplicated as they are for the Node.cloneNode() method. HTML id attributes are also cloned, which can lead to an invalid document if a partially-selected node is extracted and appened to the document.

Syntax

Standards information

Related specifications

DOM
Living Standard

Attributions