Document Object Model means a programmatic way of dealing with the structure of a Document (both XML Document or HTML document).
This is DOM: https://www.w3schools.com/xml/dom_intro.asp
But HTML adds to it: https://www.w3schools.com/jsref/dom_obj_document.asp
E.g. this is HTML not XML: https://www.w3schools.com/jsref/met_node_insertadjacenthtml.asp
BTW one well/widely understood way of dealing with this is: https://api.jquery.com/category/manipulation/
ADDENDUM: there are other ways such as Ractive’s dynamic templating.