--- title: Element.after() slug: Web/API/Element/after translation_of: Web/API/Element/after original_slug: Web/API/ChildNode/after tags: - API - DOM - Method - Node - Reference browser-compat: api.Element.after ---
Element.after()
方法会在其父节点的子节点列表中插入一些 {{domxref("Node")}} 或 {{domxref("DOMString")}} 对象。插入位置为该节点之后。{{domxref("DOMString")}} 对象会被以 {{domxref("Text")}} 的形式插入。
after(... nodes)
nodes
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>"
let container = document.createElement("div"); let p = document.createElement("p"); container.appendChild(p); p.after("Text"); console.log(container.outerHTML); // "<div><p></p>Text</div>"
let container = document.createElement("div"); let p = document.createElement("p"); container.appendChild(p); let span = document.createElement("span"); p.after(span, "Text"); console.log(container.outerHTML); // "<div><p></p><span></span>Text</div>"
{{Compat}}