Introduction to the DOM
What the Document Object Model is and the W3C DOM standard.
What is the Document Object Model (DOM)?
- The DOM is a programming interface for HTML and XML documents.
- It represents the document's content as a structured, hierarchical set of objects.
- It allows developers to access and modify content, structure and style dynamically.
- It is represented as a tree-like structure — every element, attribute and text is a node.
- The top-level node is the
documentobject, representing the entire page. - It is accessible and manipulable using programming languages such as JavaScript.
The W3C DOM Standard
“The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.”
| Part | Purpose |
|---|---|
| Core DOM | Standard model for all document types. |
| XML DOM | Standard model for XML documents. |
| HTML DOM | Standard model for HTML documents. |
Activity — complete the code
Complete the code correctly to mark this lesson as complete automatically.
Complete the script that finds, changes and styles an element.
<html><body><p id="intro">Hello World!</p><script>// 1. Find the elementvar x = document.("intro");// 2. Change its contentx. = "The DOM is a programming interface.";// 3. Change its stylex.style. = "red";</script></body></html>