HTML and CSS Reference
sprouting as branches to leaves of content. A browser—or for that matter, any
sotware parsing a web page—builds this tree structure in its memory. his in-
memory representation is called the Document Object Model (DOM).
In HTML5, the DOM is central to the interpretation of an HTML document
and its presentation as a web page. he DOM provides a map of the structure
of an HTML document and describes how its various parts work together.
he DOM also provides interfaces for assigning CSS styles to various page
elements and methods that can be called to dynamically manipulate those ele-
he language of the DOM is diferent from the language of HTML. It is like
a marriage of two people with diferent family backgrounds. HTML comes
from the family of markup languages, whereas the DOM family background
is object-oriented programming. In HTML, the web page is composed of
elements, and elements can have attributes. In working with the DOM, each
HTML element and attribute becomes a DOM object , and the HTML attribute
values become properties of those objects.
Your favorite browser has a DOM built in—probably more than one. Most
browsers use the W3C's DOM, but HTML is still evolving. “Edge” conditions
exist in which browsers difer in their interpretation of a given bit of HTML.
his is like a natural language such as English, where the word “knickers”
means something diferent in the United Kingdom than it does in the United
States. Fortunately, browsers are allowed to gracefully ignore any markup they
can't understand and not be embarrassed by the encounter. Humans are not
so lucky. We have an obligation to write code that makes sense to all web user
agents—browsers, robots, and authoring tools.
On a web page, every HTML element corresponds to a DOM object, and the
HTML attributes of the elements are properties of their DOM objects. If an
HTML element is contained inside another HTML element, the nested, inner
object is considered a property of the outer, containing object. It is referred to
as a child of the containing object, and the containing object is referred to as
the parent object. he text content inside any HTML element is also consid-
ered a property of its parent DOM object. Each object has one and only one
parent object, except for the window object corresponding to the outermost
he window object is the window or tab that is currently active in your
browser. he web page loaded into the window corresponds to a document