extractContents
Summary
Removes the contents of a range from a document or document fragment and puts it a new document fragment.
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 code | Description |
---|---|
S_OK | The operation completed successfully. |
InvalidStateError | detach has been invoked on the object. |
W3Exception_DOM_HIERARCHY_REQUEST_ERR | A document type node is included in the range that is being cloned. |
W3Exception_DOM_NO_MODIFICATION_ALLOWED_ERR | A 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
Mozilla Developer Network : [Range.extractContents Article]
Microsoft Developer Network: [extractContents Method Article]