.append()
void ParentNode.append((Node or String)... nodes)
Warning! Current browsers do not yet support
.append()
, please
use a polyfill
until they do.
Append one or more nodes to the end of a node’s child list.
node.append(nodes);
Inserts nodes after the last child of node, while replacing strings in nodes with equivalent text nodes.
See also: .prepend()
Example
HTML:
<p>
All
<strong>large</strong>
goats
<em>are</em>
delicious!
</p>
JavaScript:
let el = document.createElement("strong");
el.textContent = "Eat";
document.query("p").append(el, " them quickly.");
Resulting HTML:
<p>
All
<strong>large</strong>
goats
<em>are</em>
delicious!
<strong>Eat</strong>
them quickly.
</p>