The Document Object Model (DOM) level one provides a mechanism for software developers and web script authors to access and manipulate parsed HTML and XML content. This document defines a set of objects that extends the Document Object Model (Core) such that the combination can represent all parts of a parsed HTML document. This document is meant to be concurrent with the HTML version 4.0 specification.
This specification is part of the W3C Document Object Model, which defines a programming interface for manipulating HTML and XML documents. Objects and methods which are used for both HTML and XML documents are defined in the W3C DOM Level One Core specification, which forms the basis for the W3C DOM Level One HTML specification that you are now reading. This document extends the Level One Core specification to describe objects and methods specific to HTML documents. In general, the functionality needed to manipulate hierarchical document structures, elements, and attributes will be found in the core specification; functionality that depends on the specific elements defined in HTML will be found in this document. Another document, the W3C DOM Level One XML specification, contains methods and objects specific to XML documents.
The goals of the HTML-specific DOM specification are:
The key differences between the core DOM and the HTML application of DOM is that the HTML Document Object Model exposes a number of convenience methods and properties that are consistent with the existing models and are more appropriate to script writers. In many cases, these enhancements are not applicable to a general DOM because they rely on the presence of a predefined DTD. For DOM Level 1, the DTD for HTML 4.0 is assumed.
The W3C DOM Working Group attempts, wherever possible, to maintain compatibility with the DOM Level 0, which is defined as being the functionality exposed in Netscape Navigator 3.0 and Microsoft Internet Explorer 3.0.
More specifically, this document includes the following specializations for HTML:
The Level 1 document does not include mechanisms to access and modify style specified through CSS-1. Furthermore, it will not define an event model for HTML documents. This functionality will be specified in a future Level of this specification. The events that are supported in Level 0 are given in the DOM Level 1 HTML ECMAScript binding for completeness; the method of defining and handling events is expected to change.
The HTML DOM follows a naming convention for properties, methods, events, collections, and data types. All names are defined as one or more English words concatenated together to form a single string.
The property or method name starts with the initial keyword in lowercase, and each subsequent word starts with a capital letter. For example, a property that returns document meta information such as the date the file was created might be named "fileDateCreated". In the ECMAScript binding, properties are exposed as properties of a given object. In Java, properties are exposed with get and set methods.
The HTMLDocument is the root of the HTML hierarchy and contains the entire content as its descendants.
The following properties have been deprecated in favor of the corresponding ones for the BODY element:
The following methods allow a user to add to or replace the structure model of a document using strings of unparsed HTML. The Working Group is currently considering alternate methods for providing similar functionality for both HTML and XML documents. The following methods may be deprecated at some point in the future in favor of a more general-purpose mechanism.
The location object parses the URL for the current page into a number of properties providing easy access. The Location object is included in the HTML-specific interface ("window") in Level 0. In a subsequent level of the DOM, the DocumentContext object will be defined as part of the core API and the Location object and its methods may be deprecated.
Element | +--- HTMLElement | +--- Specific HTML Elements HTMLElement Object Hierarchy
All HTML attributes are exposed as properties on the element object. The name of the exposed property always uses the naming conventions, and is independent of the case of the attribute in the source document. The data type of the property is determined by the type of the attribute as determined by the HTML 4.0 DTD. The attributes have the semantics given in the HTML 4.0 specification.
The attributes are exposed as properties for compatibility with Level 0. This usage is deprecated because it can not be generalised to all possible attribute names, as is required both for XML and potentially for future versions of HTML. We are considering how best to add, get, and remove attributes in a simple and direct way.
DTD Data Type | Object Model Data Type |
---|---|
CDATA | String |
Value list (e.g.. (left | right | center)) | String |
one-value Value list (e.g. (border)) | Boolean |
Number | Long Integer |
The return value of an attribute that has data type that is a value list is always capitalized, independent of the case of the value in the source document. For example, if the value of the align attribute on a P element is "left" then it is returned as "Left". For attributes with the CDATA data type, the value is returned with the capitalization as in the source document.
To avoid name-space conflicts, an attribute with the same name as a keyword in one of our chosen binding languages will be prefixed. For HTML, the prefix used is "html" and for CSS, the prefix used is "css". For example, the "for" attribute collides with loop construct naming conventions and is named "htmlFor", while the CSS float attribute collides with the float data type and is named "cssFloat".
The property that exposes the element type name will return this in uppercase. For example, the body element type name is exposed through the "tagName" property as "BODY".
All HTML elements derive from this class. Elements that only expose the core attributes are represented by the base HTMLElement class. These elements are as follows:
The LINK element specifies a link to an external resource, and defines this document's relationship to that resource (or vice versa).
The document title
This contains generic meta-information about the document.
Document base URL
Represents the deprecated ISINDEX element in HTML (used for single-line text input).
Style information - a more detailed stylesheet object model will be defined in a separate document.
The HTML document body. This element is always present in the DOM API, even if the tags are not present in the source document.
If any of the form control elements is not contained within a form, the form property returns null.
The form element encompasses behavior similar to a collection and an element. It provides direct access to the contained input elements as well as the attributes of the form element.
The select element allows the selection of an option. The contained options can be directly accessed through the select element as a collection.
A selectable choice
Form control
Security Notes: Depending upon the environment the page is being viewed, the value property may be read-only for the file upload input type. For the password input type, the actual value returned may be masked to prevent unauthorized use.
Multi-line text field
Push button
Form field label text
Fieldset legend
Unordered list.
Ordered list.
Definition list, directory list, menu list
List item
Generic container
Paragraph
Headings
Quoted text
Base font
Local change to font
Inserted or deleted text
Anchor
Embedded image
Generic embedded object
Note: In principle, all properties on the object element are read-write but in some environments some properties may be read-only once the underlying object is instantiated.
Client side image map
Client side image map area
The create* and delete* methods on the table provide easy access to construct and modify tables. HTML 4.0 defines that only 1 CAPTION, THEAD and TFOOT can exist in a table. If one exists, and the createTHead() or createTFoot() method is called, the method returns the THead or TFoot element that already exists.
Table Caption
The rowIndex returns the index relative to the entire table, and sectionRowIndex returns the index relative to the section the element is scoped within (THead, TFoot, or TBody)
Subwindow
Inline subwindows
Forced line break
Script statements
Horizontal rule
This contains the complete IDL definitions for the HTML support provided by the Document Object Model.
//hb////-*-Mode: C++-*-//////////////////////////////////////////////////////// // // // NAME : // // DESCRIPTION : // // HISTORY : // // // //he/////////////////////////////////////////////////////////////////////////// interface HTMLStyle { // Hook for later level }; interface NamedNodeList { readonly attribute long length; Node item(in long index); Node namedItem(in wstring name); }; interface HTMLDocument : Document { // These are all methods, because they do some processing // of the document NamedNodeList getImages(); NamedNodeList getApplets(); NamedNodeList getLinks(); NamedNodeList getForms(); NamedNodeList getAnchors(); wstring getCookie(); wstring setCookie(in wstring cookie); readonly attribute wstring referrer; readonly attribute wstring fileSize; readonly attribute wstring fileCreatedDate; readonly attribute wstring fileModifiedDate; readonly attribute wstring fileUpdatedDate; readonly attribute wstring title; readonly attribute wstring domain; readonly attribute wstring URL; attribute HTMLElement body; void open(); void write(in wstring text); void writeln(in wstring text); void close(); }; interface HTMLElement : Element { attribute wstring className; attribute wstring id; attribute HTMLStyle style; attribute wstring title; attribute wstring lang; attribute wstring dir; }; interface HTMLLinkElement : HTMLElement { attribute wstring href; attribute wstring rel; attribute wstring rev; attribute wstring type; attribute wstring media; attribute wstring charset; attribute wstring hreflang; attribute wstring target; attribute boolean disabled; }; interface HTMLTitleElement : HTMLElement { attribute wstring text; }; interface HTMLMetaElement : HTMLElement { attribute wstring httpEquiv; attribute wstring content; attribute wstring name; attribute wstring scheme; }; interface HTMLBaseElement : HTMLElement { attribute wstring href; attribute wstring target; }; interface HTMLIsIndexElement : HTMLElement { attribute wstring prompt; }; interface HTMLStyleElement : HTMLElement { attribute wstring type; attribute boolean disabled; attribute wstring media; }; interface HTMLBodyElement : HTMLElement { attribute wstring background; attribute wstring bgColor; attribute wstring text; attribute wstring link; attribute wstring vlink; attribute wstring alink; }; interface HTMLFormElement : HTMLElement { attribute wstring action; attribute wstring method; attribute wstring target; attribute wstring name; readonly attribute long length; attribute wstring enctype; attribute wstring acceptCharset; attribute NamedNodeList elements; }; interface HTMLSelectElement : HTMLElement { attribute long selectedIndex; attribute long size; attribute boolean multiple; attribute wstring name; readonly attribute wstring type; attribute wstring value; attribute boolean disabled; attribute long length; attribute long tabIndex; readonly attribute HTMLFormElement form; attribute NamedNodeList options; void add(in HTMLElement element, in HTMLElement before); void remove(in long index); void blur(); void focus(); }; interface HTMLOptionElement : HTMLElement { attribute wstring text; attribute long index; attribute wstring value; attribute boolean defaultSelected; attribute boolean disabled;
attribute wstring label; readonly attribute boolean selected; readonly attribute HTMLFormElement form; }; interface HTMLFieldSetElement : HTMLElement { attribute wstring align; }; interface HTMLLegendElement : HTMLElement { attribute wstring align; }; interface HTMLInputElement : HTMLElement { readonly attribute wstring type; attribute wstring value; attribute wstring name; attribute boolean disabled; attribute wstring defaultValue; attribute long size; attribute long maxLength; attribute boolean readOnly; attribute boolean checked; attribute boolean defaultChecked; attribute wstring src; attribute wstring alt; attribute wstring usemap; attribute wstring align; attribute long tabIndex; attribute wstring accessKey; attribute wstring accept; readonly attribute HTMLFormElement form; void blur(); void focus(); void select(); void click(); }; interface HTMLTextAreaElement : HTMLElement { readonly attribute wstring type; attribute wstring value; attribute wstring name; attribute boolean disabled; attribute wstring defaultValue; attribute boolean readOnly; attribute long rows; attribute long cols; attribute long tabIndex; readonly attribute HTMLFormElement form; void blur(); void focus(); void select(); }; interface HTMLButtonElement : HTMLElement { readonly attribute wstring type; attribute wstring value; attribute wstring name; attribute boolean disabled; attribute long tabIndex; attribute wstring accessKey; readonly attribute HTMLFormElement form; }; interface HTMLLabelElement : HTMLElement { attribute wstring htmlFor; attribute wstring accessKey; }; interface HTMLAnchorElement : HTMLElement { attribute wstring target; attribute wstring href; attribute wstring rel; attribute wstring rev; attribute wstring name; attribute wstring accessKey; attribute long tabIndex; attribute wstring charset; }; interface HTMLBaseFontElement : HTMLElement { attribute wstring color; attribute wstring face; attribute long size; }; interface HTMLBRElement : HTMLElement { attribute wstring clear; }; interface HTMLImageElement : HTMLElement { attribute boolean isMap; attribute wstring useMap; attribute wstring border; attribute long vspace; attribute long hspace; attribute wstring alt; attribute wstring src; attribute wstring lowSrc; attribute wstring align; attribute long width; attribute long height; attribute wstring name; }; interface HTMLFontElement : HTMLElement { attribute wstring color; attribute wstring face; attribute long size; }; interface HTMLModElement : HTMLElement { attribute wstring cite; attribute wstring dateTime; }; interface HTMLObjectElement : HTMLElement { attribute wstring classId; attribute wstring data; attribute wstring align; attribute wstring name; attribute wstring codeBase; attribute wstring codeType; attribute wstring code; attribute wstring type; attribute long width; attribute long height; attribute wstring altHtml; attribute long vspace; attribute long hspace; attribute long tabIndex; readonly attribute HTMLFormElement form; }; interface HTMLQuoteElement : HTMLElement { attribute wstring cite; }; interface HTMLScriptElement : HTMLElement { attribute wstring src; attribute wstring text; attribute wstring type; attribute wstring language; attribute boolean defer; }; interface HTMLUListElement : HTMLElement { attribute boolean compact; attribute wstring type; }; interface HTMLOListElement : HTMLElement { attribute boolean compact; attribute wstring type; attribute long start; }; interface HTMLLIElement : HTMLElement { attribute wstring type; attribute long value; }; interface HTMLDListElement : HTMLElement { attribute boolean compact; }; interface HTMLDivElement : HTMLElement { attribute wstring align; }; interface HTMLHRElement : HTMLElement { attribute wstring align; attribute boolean noShade; attribute long width; attribute long size; }; interface HTMLParagraphElement : HTMLElement { attribute wstring align; }; interface HTMLHeadingElement : HTMLElement { attribute wstring align; }; interface HTMLMapElement : HTMLElement { readonly attribute NamedNodeList areas; attribute wstring name; }; interface HTMLAreaElement : HTMLElement { attribute wstring shape; attribute wstring coords; attribute wstring href; attribute wstring target; attribute wstring alt; attribute boolean noHref; attribute long tabIndex; attribute wstring accessKey; }; interface HTMLTableCaption : HTMLElement { attribute wstring align; }; interface HTMLTable : HTMLElement { attribute long cols; attribute wstring border; attribute wstring frame; attribute wstring rules; attribute long cellSpacing; attribute long cellPadding; attribute wstring bgColor; attribute wstring align; attribute long width; attribute HTMLTableCaption caption; readonly attribute HTMLTableSection thead; readonly attribute HTMLTableSection tfoot; NamedNodeList getRows(); NamedNodeList getTBodies(); HTMLElement createTHead(); void deleteTHead(); HTMLElement createTFoot(); void deleteTFoot(); HTMLTableCaption createCaption(); void deleteCaption(); HTMLElement insertRow(in long index); void deleteRow(in long index); }; interface HTMLTableCol : HTMLElement { attribute long span; attribute wstring align; attribute wstring valign; attribute long width; }; interface HTMLTableSection : HTMLElement { NamedNodeList getRows(); HTMLElement insertRow(in long index); void deleteRow(in long index); attribute wstring align; attribute wstring valign; }; interface HTMLTableRow : HTMLElement { attribute long rowIndex; attribute long sectionRowIndex; attribute wstring align; attribute wstring valign; attribute wstring bgColor; NamedNodeList getCells(); HTMLElement insertCell(in long index); void deleteCell(in long index); }; interface HTMLTableCell : HTMLElement { attribute long cellIndex; attribute long rowSpan; attribute long colSpan; attribute wstring align; attribute wstring valign; attribute wstring bgColor; attribute boolean noWrap; attribute long width; attribute long height; }; interface HTMLCommentElement : HTMLElement { attribute wstring text; }; interface HTMLFrameSetElement : HTMLElement { attribute wstring rows; attribute wstring cols; }; interface HTMLFrameElement : HTMLElement { attribute wstring src; attribute wstring name; attribute boolean noResize; attribute wstring scrolling; attribute wstring frameBorder; attribute long marginWidth; attribute long marginHeight; }; interface HTMLIFrameElement : HTMLElement { attribute wstring src; attribute wstring name; attribute wstring scrolling; attribute wstring align; attribute long marginWidth; attribute long marginHeight; attribute long width; attribute long height; };
The Java API definitions will be added in the next public release of the HTML DOM Level One.
This will contain the ECMAScript bindings for the HTML DOM.