Document Object Model

Document is the Root of the DOM Tree

The document object is a representation of the entire HTML document and is the parent of all other objects in the DOM tree.

No other node object can exist outside the document object.

Look at the example given below:

In the above example, we have used the document.querySelector method to search the whole document and find the element with the id root. Then, we used the document.createElement method to create a new element in the document.

We can see that for actions or data that relates to the whole document, we need to use the document object.