If you want it to be added at the bottom of an existing element, you want to use appendChild()
.
Start by setting the new element to a temporary variable:
var newDiv = document.createElement("div");
Then make any updates to the new element (e.g., add a class, set the id
attribute, etc.) and append it to your target element:
document.getElementById.("TARGET_ID").appendChild(newDiv);
If there is other content in the target div already, and you want to place the new element in a specific location other than the end, you can identify the appropriate child element of the target div and use insertBefore()
instead.
Lots of information on this can be found here: https://developer.mozilla.org/en-US/docs/Web/API/Node.appendChild