Name
DocumentFragment — adjacent nodes and their subtrees
Availability
DOM Level 1 Core
Inherits from/Overrides
Node → DocumentFragment
Description
The DocumentFragment interface represents a portion -- or
fragment -- of a document. More specifically, it represents one or
more adjacent Document nodes and all of the descendants of each.
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 each of the
children of the DocumentFragment instead. 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
Returned by
Document.createDocumentFragment( ), Range.cloneContents( ), Range.extractContents( )
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