What is Document Object Model (DOM)??
An API for (HTML,SVG) that offers a web page as a tree of objects.

With the DOM, programmers can build documents, navigate their structure, and add, modify, or delete elements and content. Web browsers use Dom specifications to determine how to display web pages.

Dom is language agnostic, we can use other programing languages to interact with it as well not just Javascript. What we end up seeing in the browser is based on the Dom, not just the original HTML source code.
Dom stands for Document Object Model
The DOM represents a document with a logical tree. Each branch of the tree ends in a node, and each node contains objects. DOM methods allow programmatic access to the tree. With them you can change the document’s structure, style, or content.
3 steps how to create new elements with DOM
- Create a new element by using
Document.createElement()
and give it some text content. - Manipulate the element (add styles, classes, ids, text etc.)
- Place the element into the DOM by Append Elements
The ParentNode.append()
method inserts a set of Node
objects or DOMString
objects after the last child of the ParentNode
. DOMString
objects are inserted as equivalent Text
nodes.
Differences from Node.appendChild()
:
ParentNode.append()
allows you to also appendDOMString
objects, whereasNode.appendChild()
only acceptsNode
objects.ParentNode.append()
has no return value, whereasNode.appendChild()
returns the appendedNode
object.ParentNode.append()
can append several nodes and strings, whereasNode.appendChild()
can only append one node.
