The DOM (Document Object Model) is a cross-platform API that treats HTML and XML documents as a tree structure consisting of nodes. These nodes (such as elements and text nodes) are objects that can be programmatically manipulated and any visible changes made to them are reflected live in the document. In a browser, this API is available to JavaScript where DOM nodes can be manipulated to change their styles, contents, placement in the document, or interacted with through event listeners.
<head>
with a defer attribute, or inside a DOMContentLoaded event listener. Scripts that manipulate DOM nodes should be run after the DOM has been constructed to avoid errors.document.getElementById()
and document.querySelector() are common functions for selecting DOM nodes.<div id="container"></div>
...
<script>
var container = document.getElementById("container");
container.innerHTML = "New Content!";
</script>
then it becomes
<div id="container">New Content!</div>
this also relates to AJAX, client side templating