The Element.after() method inserts one or more nodes or strings into the children list of this element’s parent, immediately after this element (MDN). Strings become Text nodes. It returns undefined.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call el.after. Start with this line.
JavaScript
el.after(node1, node2, …)
Call
What it does
el.after(node1, node2, …)
Primary signature.
el.after(...)
Call with the arguments your case needs.
Built into the browser. Call after(...) on an Element — no import required.
Library declarations
JavaScript
el.after(node1, node2, …)
Parameters
Parameter
Description
Reference element
Required. Must have a parent to insert into
node1…nodeN
Required. Node objects and/or strings
Return Value
Return Value
Description
*
Always undefined
JavaScript Examples
Example 1 — Insert an Element
Place a new sibling right after a paragraph.
JavaScript
const p = document.getElementById("p");
const out = document.getElementById("out");
const span = document.createElement("span");
span.textContent = "after";
p.after(span);
out.textContent = p.parentNode.innerHTML;
Pass several items. Nodes and strings can mix in one call.
Keep argument order. First argument is closest after p.
One DOM update pattern. Cleaner than several separate inserts.
Verify. Parent HTML shows p, then span, then text.
Compatibility
Browser Support
Element.after() is Baseline Widely available on MDN (across browsers since April 2018). It is not Deprecated, Experimental, or Non-standard. Prefer it over older sibling-insert patterns when you can.
✓ Baseline Widely available
Element.after()
Modern ChildNode insert — nodes or strings after a sibling. Widely supported since 2018.
2018+Widely available
Google Chrome54+
Supported
Mozilla Firefox49+
Supported
Apple Safari10+
Supported
Microsoft Edge17+
Supported
Opera41+
Supported
Internet ExplorerNot supported — use insertBefore
Unavailable
after()Baseline
Bottom line: Safe for modern browsers. For very old IE, use parent.insertBefore with a reference sibling.
Frequently Asked Questions
It inserts one or more Node objects or strings into the children of this element’s parent, immediately after this element (MDN). Strings become Text nodes.
No. MDN marks Element.after() as Baseline Widely available (across browsers since April 2018). It is not Deprecated, Experimental, or Non-standard.
Nothing useful — the return value is undefined. The DOM is updated in place; check parent.outerHTML or nextSibling if you need to verify the result.
Yes. after(node1, node2, …) inserts all arguments in order, right after the element you call it on.
after() is called on the sibling you want to place content after. insertBefore() is called on the parent and needs a reference child. Modern after() also accepts strings as Text nodes.
If the element is not in a parent’s child list, after() has nowhere to insert. Invalid hierarchy cases can throw a HierarchyRequestError DOMException.