C H A P T E R  31

Using the Element-Specific Objects

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.

The Document and Metadata Objects

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

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.

Image

The body Element

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.

Image

Image Tip Some browsers support these events through the window object, which I describe in Chapter 27.

The link Element

The link element is represented by the HTMLLinkElement object, which defines the properties shown in Table 31-3.

Image

The meta Element

The meta element is represented by the HTMLMetaElement object, which defines the properties shown in Table 31-4.

Image

The script Element

The script element is represented in the DOM by the HTMLScriptElement object, which defines the additional properties described in Table 31-5.

Image

The style Element

The style element is represented in the DOM by the HTMLStyleElement object, which defines the additional properties shown in Table 31-6.

Image

Image

The title Element

The title element is represented by the HTMLTitleElement object in the DOM. This object defines the property shown in Table 31-7.

Image

Other Document and Metadata Elements

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.

The Text Elements

This section describes the objects that represent the text elements. You can learn more about these elements in Chapter 8.

The a Element

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.

Image

Image

The del and ins Elements

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.

Image

The q Element

The q element is represented by the HTMLQuoteElement object. The property that this object defines is described in Table 31-10.

Image

The time Element

The time element is represented by the HTMLTimeElement object. The additional properties defined by this object are shown in Table 31-11.

Image

Other Text Elements

The br and span elements are represented by the HTMLBRElement and HTMLSpanElementobjects, 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.

The Grouping Elements

This section describes the objects that represent the grouping elements. You can learn more about these elements in Chapter 9.

The blockquote Element

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

The li element is represented by the HTMLLIElement object, which defines the property shown in Table 31-12.

Image

The ol Element

The ol element is represented by the HTMLOListElement object, which defines the properties shown in Table 31-13.

Image

Other Grouping Elements

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.

Image

Image

The following elements do not have corresponding elements in the DOM and are represented by HTMLElement: dd, dt, figcaption, and figure.

The Section Elements

This section describes the objects that represent the section elements. You can learn more about these elements in Chapter 10.

The details Element

The details element is represented by the HTMLDetailsElement object. The property that this object defines is described in Table 31-15.

Image

Other Section Elements

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.

The Table Elements

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

The col and colgroup elements are both represented by the HTMLTableColElement object, which defines the property shown in Table 31-16.

Image

The table Element

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.

Image

The thead, tbody, and tfoot Elements

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.

Image

The th Element

The th element is represented by the HTMLTableHeaderCellElement object. The property defined by this object is described in Table 31-19.

Image

The tr Element

The tr element is represented by the HTMLTableRowElement object, which defines the properties and methods shown in Table 31-20.

Image

Image

Other Table Elements

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.

Image

The Form Elements

This section describes the objects that represent the form elements. You can learn more about these elements in Chapters 1214.

The button Element

The button element is represented by the HTMLButtonElement object, which defines the properties and methods shown in Table 31-22.

Image

Image

The datalist Element

The datalist element is represented by the HTMLDataListElement object, which defines the property shown in Table 31-23.

Image

The fieldset Element

The fieldset element is represented by the HTMLFieldSetElement object, which defines the properties shown in Table 31-24.

Image

The form Element

The form element is represented by the HTMLFormElement object, which defines the properties and methods shown in Table 31-25.

Image

The input Element

The input element is represented by the HTMLInputElement object, which supports the properties and methods shown in Table 31-26.

Image

Image

The label Element

The label element is represented by the HTMLLabelElement object, which defines the properties shown in Table 31-27.

Image

The legend Element

The legend element is represented by the HTMLLegendElement object, which defines the property shown in Table 31-28.

Image

The optgroup Element

The optgroup element is represented by the HTMLOptGroupElement object, which defines the properties shown in Table 31-29.

Image

The option Element

The option element is represented by the HTMLOptionElement object, which defines the properties shown in Table 31-30.

Image

The output Element

The output element is represented by the HTMLOutputElement object, which defines the properties shown in Table 31-31.

Image

Image

The select Element

The select element is represented by the HTMLSelectElement object, which implements the properties and methods shown in Table 31-32.

Image

Image

The textarea Element

The textarea element is represented by the HTMLTextAreaElement object, which defines the methods and properties described in Table 31-33.

Image

Image

The Content Elements

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.

Image Note The other content elements, such as canvas and video, are described later in Chapter 34.

The area Element

The area element is represented by the HTMLAreaElement, which implements the properties shown in Table 31-34.

Image

Image

The embed Element

The embed element is represented by the HTMLEmbedElement object, which implements the properties shown in Table 31-35.

Image

Image

The iframe Element

The iframe element is represented by the HTMLIFrameElement object, which implements the properties described in Table 31-36.

Image

The img Elements

The img element is represented by the HTMLImageElement object, which implements the properties described in Table 31-37.

Image

Image

The map Element

The map element is represented by the HTMLMapElement object, which implements the properties shown in Table 31-38.

Image

The meter Element

The meter element is represented by the HTMLMeterElement object, which implements the properties shown in Table 31-39.

Image

The object Element

The object element is represented by the HTMLObjectElement object, which implements the properties shown in Table 31-40.

Image

The param Element

The param element is represented by the HTMLParamElement object, which implements the properties shown in Table 31-41.

Image

The progress Element

The progress element is represented by the HTMLProgressElement object, which implements the properties shown in Table 31-42.

Image

Summary

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.26.158