Saturday, December 6, 2008

What is the DOM?

The Document Object Model, or DOM, is an interface to allow programs and scripts to update content, structure, and style of documents dynamically. It is platform- and language-neutral. The DOM is not HTML nor is it JavaScript. It is something like the glue that binds them together.

DOM Level 0

The DOM level 0 is a mix of HTML functions that have not been formally specified that allow scripting languages to interact with Microsoft Internet Explorer 3.0 and Netscape Navigator 3.0. This basically means that if a DHTML page is compliant with DOM level 0 it should work reliably even in fairly old browsers.

The base structure of the DOM level 0 is the document master container. This refers to the entire document, and all elements within it. It is referenced as:


Because the DOM level 0 is very basic, it only allows the developer to manipulate items on the page that already have some level of interactivity, i.e. forms. It is possible to reference other items in a Web document, but most browsers don't support much interactivity with them at level 0.

Referencing Forms

There are three ways to reference a form control using DOM level 0:

by name or id
This is the easiest way to reference a form control, as you can clearly see in the XHTML which form you a referring to. For example, this form is named "form1":

<form name="form1" id="form1">...</form>

It would be referenced in the DOM as:


Then if you wanted to reference an element within the form, you would name it as well:



<input type="text" name="fname" />

in the above form.

by number
Each form, and element within the form, is given a number in an array, starting with 0. They are numbered starting with the first

element found in the flow of the document. So, to reference the second form on the page:


Then, to reference the second form element within the second form:


a combination of both
It is possible to use any combination of number or name to reference a form or form element within the document:


Labels: ,


Post a Comment

Subscribe to Post Comments [Atom]

<< Home