Web Technology Basics
Which of the following correctly describes the DOM (Document Object Model) used in browsers?
- AA form into which the table structure of a server's database is converted, as HTML tables (table elements), to be sent to the browser
- BA representation of an HTML document as a tree whose nodes are elements and so on, which JavaScript can read and write
- CA format in which CSS rules are compressed by removing whitespace, to make files smaller and load faster
Show answer and explanation
Answer: B. A representation of an HTML document as a tree whose nodes are elements and so on, which JavaScript can read and write
The browser parses HTML and builds a tree structure (the DOM tree) whose root is the html element and whose nodes include head, body and the paragraphs inside them. JavaScript changes the page through the DOM, finding elements with document.querySelector, rewriting text and attributes, and adding elements. When the DOM changes, the browser redoes the layout calculation and painting as needed. The DOM is standardized as an interface for manipulating documents that does not depend on any particular programming language.
- A. The DOM is the structure of the document inside the browser and has nothing to do with databases.
- B. Correct. It represents the document as a tree so that scripts can manipulate it.
- C. It has nothing to do with compressing CSS. The structure built from CSS is called the CSSOM.