Removes the contents of a range from a document or document fragment and puts it a new document fragment.
var documentFragment = range.extractContents(/* see parameter list */);
Returns an object that contains the extracted content.
Returns an object of type DOM NodeDOM Node
This method can return one of these values.
|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.|
range = document.createRange(); range.selectNode(document.getElementsByTagName("div").item(0)); documentFragment = range.extractContents(); document.body.appendChild(documentFragment);
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.
- Living Standard