DOM stands for Document Object Model, the tree of objects a browser builds from an HTML document and exposes to JavaScript so code can read, add, move and remove parts of the page. It is defined by the WHATWG DOM Standard, a living standard that describes a platform-neutral model for events, aborting activities and node trees. When you call document.querySelector, you are using it.
The browser parses HTML into nodes that form a tree. Every node implements the Node interface, and most you work with are more specific types: Document, DocumentType, DocumentFragment, Element, CharacterData (text, comments, CDATA sections and processing instructions) and Attr. The Document sits at the root and gives you the entry points such as querySelector and createElement.
Each node has a numeric nodeType. The values defined by the standard are:
Changing the tree changes what the browser renders. The DOM is also the event system: you attach listeners to nodes with addEventListener, and events travel through the tree in a capture phase, at the target, then a bubble phase (constants 1, 2 and 3 in the standard).
document.body.innerHTML = '<ul id=l><li>one</li><li>two</li></ul>';
const l = document.getElementById('l');
const li = document.createElement('li');
li.textContent = 'three';
l.append(li);
console.log([l.children.length, l.outerHTML, l.nodeType, l.firstChild.firstChild.nodeType, document.nodeType].join(' | '));
Output from headless Chromium 141:
3 | <ul id="l"><li>one</li><li>two</li><li>three</li></ul> | 1 | 3 | 9
The list has three children after the append. The ul is node type 1, the text inside its first li is type 3, and the document is type 9.
No. The HTML source is text, and the DOM is the live object tree built from it, so the two can differ. Scripts can change the DOM after load, so the Elements panel in developer tools may show nodes that view-source does not. The DOM is also not part of the JavaScript language: In Node.js 22, typeof document is undefined unless you add a library such as jsdom.
<b>x</b> created 1 child element, while textContent with the same string created 0. Use textContent for plain text, since markup in user input otherwise becomes real elements. See XSS.