let container = document.createElement("div");
let p = document.createElement("p");
container.appendChild(p);
let span = document.createElement("span");
p.after(span);
console.log(container.outerHTML);
// "<div><p></p><span></span></div>"Element: after() method / notebook
Element: after() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const container = document.createElement("div");
const p = document.createElement("p");
container.appendChild(p);
p.after("Text");
console.log(container.outerHTML);
// "<div><p></p>Text</div>"const container = document.createElement("div");
const p = document.createElement("p");
container.appendChild(p);
const span = document.createElement("span");
p.after(span, "Text");
console.log(container.outerHTML);
// "<div><p></p><span></span>Text</div>"