Visit Mozilla.org

DOM:range.extractContents

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Moves contents of a Range from the document tree into a document fragment.

[edit] Syntax

documentFragment = range.extractContents();

[edit] Example

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

[edit] Notes

Event Listeners added using DOM Events are not retained during extraction. HTML attribute events are retained or duplicated as they are for the DOM Core 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.

Partially selected nodes are cloned to include the parent tags necessary to make the document fragment valid.

[edit] Specification

extractContents