Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14
Chapter 6

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 document object, 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.”

PartPurpose
Core DOMStandard model for all document types.
XML DOMStandard model for XML documents.
HTML DOMStandard 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 element
var x = document.("intro");
 
// 2. Change its content
x. = "The DOM is a programming interface.";
 
// 3. Change its style
x.style. = "red";
</script>
</body>
</html>