Home

createDocumentFragment

createDocumentFragment is a method on the Document interface in the Web Platform. It creates and returns a new DocumentFragment, which is a lightweight, invisible container used to hold nodes temporarily before they are inserted into the live document.

A DocumentFragment acts as a minimal subtree that is not part of the main DOM tree. You

Typical usage involves creating the fragment, populating it with nodes, and then appending it to a target

Notes and considerations: a DocumentFragment contains nodes but has no parent, and it cannot be styled as

can
append
or
manipulate
multiple
nodes
inside
the
fragment,
then
insert
the
fragment
into
the
document
in
a
single
operation.
This
can
improve
performance
by
reducing
the
number
of
reflows
and
repaints,
since
the
browser
only
needs
to
render
once
when
the
fragment
is
finally
appended.
element.
For
example,
you
might
build
a
list
of
items
by
creating
a
fragment,
adding
several
list
item
elements
to
it,
and
then
appending
the
fragment
to
an
existing
ul
or
ol.
When
the
fragment
is
appended
to
the
document,
its
children
are
moved
into
the
document
in
place
of
the
fragment
itself,
and
the
fragment
becomes
empty.
a
unit.
It
is
primarily
a
performance
and
organizational
aid
for
constructing
or
cloning
multiple
nodes
before
insertion.
Browser
support
for
createDocumentFragment
is
extensive
across
modern
browsers
and
has
been
part
of
the
DOM
specification
for
many
years.