The Document Object Model (DOM) defines a set of objects that represent the different types of HTML elements in a document. These objects can be treated as HTMLElement
objects and, for the most part, that’s what you typically do in your scripts. But if you want to access some attribute or feature that is unique to an element, you can usually do so using one of these objects.
These objects are not much use. They generally define properties that correspond to attributes supported by an element, the value of which you can access through the features of the HTMLElement
. There are a couple of exceptions—the form elements have some helpful methods for use with input validation, and the table elements have some methods that can be used to build up the content of tables.
This section describes the objects that represent the data and metadata elements. You can learn more about these elements in Chapter 7.
The base
element is represented by the HTMLBaseElement
object. This object doesn’t define any additional events, but there are two properties, which are shown in Table 31-1.
The body
element is represented by the HTMLBodyElement
object. This object doesn’t define any additional properties, but the set of events is shown in Table 31-2.
Tip Some browsers support these events through the window
object, which I describe in Chapter 27.
The link
element is represented by the HTMLLinkElement
object, which defines the properties shown in Table 31-3.
The meta
element is represented by the HTMLMetaElement
object, which defines the properties shown in Table 31-4.
The script
element is represented in the DOM by the HTMLScriptElement
object, which defines the additional properties described in Table 31-5.
The style
element is represented in the DOM by the HTMLStyleElement
object, which defines the additional properties shown in Table 31-6.
The title
element is represented by the HTMLTitleElement
object in the DOM. This object defines the property shown in Table 31-7.
The head
and html
elements are represented by the HTMLHeadElement
and HTMLHtmlElement
objects, respectively. These objects do not define any additional methods, properties, or events beyond those of HTMLElement
. The noscript
element doesn’t have a special DOM object and is represented solely by HTMLElement
.
This section describes the objects that represent the text elements. You can learn more about these elements in Chapter 8.
The a
element is represented by the HTMLAnchorElement
object, which defines the properties shown in Table 31-8. In addition to defining properties that correspond to the element attributes, this object defines a set of convenience properties that allows you to easily get or set components of the URL specified by the href
attribute.
The del
and ins
elements are both represented by the HTMLModElement
. You can tell them apart using the tagName
property defined by HTMLElement
. See Chapter 26 for details. The additional properties defined by HTMLModElement
are described in Table 31-9.
The q
element is represented by the HTMLQuoteElement
object. The property that this object defines is described in Table 31-10.
The time
element is represented by the HTMLTimeElement
object. The additional properties defined by this object are shown in Table 31-11.
The br
and span
elements are represented by the HTMLBRElement
and HTMLSpanElement
objects, respectively. These objects do not define any additional methods, properties, or events beyond those of HTMLElement
. The following elements are represented solely by HTMLElement
: abbr
, b
, cite
, code
, dfn
, em
, i
, u
, kbd
, mark
, rt
, rp
, ruby
, s
, samp
, small
, strong
, sub
, sup
, var
, and wbr
.
This section describes the objects that represent the grouping elements. You can learn more about these elements in Chapter 9.
The blockquote
element is represented by the HTMLQuoteElement
object. This is the same object that the q
element uses, which I described in Table 31-10.
The li
element is represented by the HTMLLIElement
object, which defines the property shown in Table 31-12.
The ol
element is represented by the HTMLOListElement
object, which defines the properties shown in Table 31-13.
Table 31-14 shows the set of grouping elements that are represented by element-specific objects that do not define any additional functionality beyond that of HTMLElement
.
The following elements do not have corresponding elements in the DOM and are represented by HTMLElement
: dd
, dt
, figcaption
, and figure
.
This section describes the objects that represent the section elements. You can learn more about these elements in Chapter 10.
The details
element is represented by the HTMLDetailsElement
object. The property that this object defines is described in Table 31-15.
The h1
-h6
elements are represented by the HTMLHeadingElement
object, but this object doesn’t define any additional properties. The following section elements are not represented by specific objects: address
, article
, aside
, footer
, header
, hgroup
, nav
, section
, and summary
.
This section describes the objects that represent the table elements. You can learn more about these elements in Chapter 11.
The col
and colgroup
elements are both represented by the HTMLTableColElement
object, which defines the property shown in Table 31-16.
The table
element is represented by the HTMLTableElement
object. This is one of the most useful of the element-specific objects. The properties and methods defined by this object are described in Table 31-17.
The thead
, tbody
, and tfoot
elements are all represented by the HTMLTableSectionElement
object. The property and methods defined by this object are shown in Table 31-18.
The th
element is represented by the HTMLTableHeaderCellElement
object. The property defined by this object is described in Table 31-19.
The tr
element is represented by the HTMLTableRowElement
object, which defines the properties and methods shown in Table 31-20.
Table 31-21 shows the set of table elements that are represented by element-specific objects that do not define any additional functionality beyond that of HTMLElement
.
This section describes the objects that represent the form elements. You can learn more about these elements in Chapters 12–14.
The button
element is represented by the HTMLButtonElement
object, which defines the properties and methods shown in Table 31-22.
The datalist
element is represented by the HTMLDataListElement
object, which defines the property shown in Table 31-23.
The fieldset
element is represented by the HTMLFieldSetElement
object, which defines the properties shown in Table 31-24.
The form
element is represented by the HTMLFormElement
object, which defines the properties and methods shown in Table 31-25.
The input
element is represented by the HTMLInputElement
object, which supports the properties and methods shown in Table 31-26.
The label
element is represented by the HTMLLabelElement
object, which defines the properties shown in Table 31-27.
The legend
element is represented by the HTMLLegendElement
object, which defines the property shown in Table 31-28.
The optgroup
element is represented by the HTMLOptGroupElement
object, which defines the properties shown in Table 31-29.
The option
element is represented by the HTMLOptionElement
object, which defines the properties shown in Table 31-30.
The output
element is represented by the HTMLOutputElement
object, which defines the properties shown in Table 31-31.
The select
element is represented by the HTMLSelectElement
object, which implements the properties and methods shown in Table 31-32.
The textarea
element is represented by the HTMLTextAreaElement
object, which defines the methods and properties described in Table 31-33.
This section describes the objects that represent the elements used to embed content in a document. You can learn more about these elements in Chapter 15.
Note The other content elements, such as canvas
and video
, are described later in Chapter 34.
The area
element is represented by the HTMLAreaElement
, which implements the properties shown in Table 31-34.
The embed
element is represented by the HTMLEmbedElement
object, which implements the properties shown in Table 31-35.
The iframe
element is represented by the HTMLIFrameElement
object, which implements the properties described in Table 31-36.
The img
element is represented by the HTMLImageElement
object, which implements the properties described in Table 31-37.
The map
element is represented by the HTMLMapElement
object, which implements the properties shown in Table 31-38.
The meter
element is represented by the HTMLMeterElement
object, which implements the properties shown in Table 31-39.
The object
element is represented by the HTMLObjectElement
object, which implements the properties shown in Table 31-40.
The param
element is represented by the HTMLParamElement
object, which implements the properties shown in Table 31-41.
The progress
element is represented by the HTMLProgressElement
object, which implements the properties shown in Table 31-42.
In this chapter, I listed the set of objects that are used to represent different types of elements in the DOM. For the most part, these are not especially useful—with two exceptions. The first exception is the form elements, which provide some useful control over validation and form submission. The second exception is the table elements, which provide methods for managing the content of tables. These exceptions aside, the objects described in this chapter are largely a collection of properties that represent specific attributes—the values of which can be accessed through the ubiquitous HTMLElement
object.
18.188.26.158