Accessing the DOM Structure

For JavaScript running in a browser, the displayed document can be accessed through the document global variable. This is not itself part of the Composite structure (it has type HTMLDocument), but it does provide access to the structure through its variable document.documentElement. This is an element of type HTMLHtmlElement, representing the <html> tag and its contents.

Usually, document elements are accessed by invoking search methods that are provided by the document variable. Element methods give JavaScript programmers the capability of adding and removing children and modifying their attributes such as their HTML class and their ids. The textual content of a Text element is easily modified by altering one of its attributes. Comment elements are rarely accessed since they do not affect the display of a web page.

The attributes of elements in a document hierarchy can often be modified by JavaScript code. Assigning a new value to an attribute works like using a setter method in Java - it can have side effects. All modifiable attributes that affect the display of a document have updating the display as a side effect.

In the following web pages, all attributes are modifiable except those that are described as read-only.