HTML DOM Element after()
Example
Insert text after a div:
const div = document.getElementById("myDiv");
div.after("World!");
Try it Yourself »
Example
Insert an element after a div:
const div = document.getElementById("myDiv");
const h3 =
document.createElement("h3");
div.after(h3);
h3.append("Hello! I am an
h3");
Try it Yourself »
More "Try it Yourself" examples below.
Description
The after()
method is used to insert one or
more nodes (elements)
or strings immediately after an element.
Tip: Strings will be inserted as Text nodes.
Syntax
element.after(node1, node2, ...)
Parameters
Parameter | Description |
node | Required. One or more nodes or strings to insert after the element |
Return Value
None
Browser Support
Method | |||||
---|---|---|---|---|---|
after() | 54 | 17 | 49 | 10 | 39 |
See Also:
Related Document Methods:
More Examples
Example
Insert two elements and a text after a div:
const div = document.getElementById("myDiv");
const h3 =
document.createElement("h3");
const h4 = document.createElement("h4");
div.after(h3, h4, "Some text!");
h3.append("Hello! I am an h3");
h4.append("Hello! I am an h4");
Try it Yourself »