Name
DocumentFragment — adjacent nodes and their subtrees
Inherits from
Node
Synopsis
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 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.
You can create a new, empty DocumentFragment with Document.createDocumentFragment()
.
You can search for elements in a DocumentFragment with
querySelector()
and querySelectorAll()
, which work
just like the same methods of the Document object.
Methods
Element querySelector
(string
selectors
)
querySelector
(string
selectors
)See Document.querySelector()
.
NodeList querySelectorAll
(string
selectors
)
querySelectorAll
(string
selectors
)See Document.querySelectorAll()
.
Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.