DOM (JavaScript)

The DOM (Document Object Model) is a live, tree-shaped representation of an HTML page that JavaScript can read and change. Editing the DOM updates what the user sees.

JavaScript

The browser turns your HTML into the DOM, a tree of nodes (elements, text, attributes). JavaScript uses the document object to find, create, and modify these nodes.

Methods like document.querySelector() let you grab elements, and properties like textContent or classList let you change them.

Examples

JavaScript

const heading = document.querySelector("h1");
heading.textContent = "Updated!";
console.log(heading.textContent);

Output:

Updated!

Learn it in a lesson

See also

Back to the Dictionary