Home

afterbegin

Afterbegin is a keyword used in several DOM insertion methods to specify where new content should be inserted relative to an element. It is one of the four insertion positions accepted by insertAdjacentHTML, insertAdjacentElement, and insertAdjacentText: beforebegin, afterbegin, beforeend, and afterend.

When used with an element, afterbegin inserts the supplied content immediately after the opening tag, making

Example: given a div that currently contains the text Hello, applying insertAdjacentHTML('afterbegin', '<span>Hi</span>') would result in

Compatibility: The insertion methods that use the afterbegin position are supported in all modern major browsers.

Notes: Afterbegin is a positional keyword that, in common use, is passed as a string argument to

it
the
first
child
of
the
element.
If
the
element
already
contains
children,
the
new
content
becomes
the
first
child;
if
the
element
is
empty,
the
content
becomes
the
only
child.
a
structure
like
<div><span>Hi</span>Hello</div>.
Older
or
very
old
browsers
that
do
not
implement
these
methods
may
not
recognize
this
position.
the
relevant
insertion
methods,
guiding
where
the
new
content
should
be
placed
within
the
target
element.
It
is
part
of
a
set
of
related
positions
that
control
insertion
relative
to
the
element
versus
around
it.