Name
DocumentFragment: adjacent nodes and their subtrees — DOM Level 1 Core: Node → DocumentFragment
Description
The DocumentFragment interface represents a portion—or
fragment—of a document. More specifically, it is a list of adjacent
nodes and all descendants of each, but without any common parent
node. DocumentFragment nodes are never part of a document tree, and
the inherited parentNode property
is always null. DocumentFragment
nodes exhibit a special behavior that makes them quite useful,
however: when a request is made to insert a DocumentFragment into a
document tree, it is not the DocumentFragment node itself that is
inserted but it is instead each child of the DocumentFragment. This
makes DocumentFragment useful as a temporary placeholder for nodes
that you wish to insert, all at once, into a document.
DocumentFragment is also particularly useful for implementing
document cut, copy, and paste operations, particularly when combined
with the Range interface.
You can create a new, empty DocumentFragment with Document.createDocumentFragment( ), or you
can use Range.extractContents( )
or Range.cloneContents( ) to
obtain a DocumentFragment that contains a fragment of an existing
document.
See Also
Range
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access