VirtualMV/JavaScript/DocumentObject/Home

Overview
In order for a computer to understand a document, it needs to follow a pre-defined structure built up of identifiable objects (document objects).

On a computer the term document is used to represent many file types, indeed we use folders to arrange computer documents (files?) including Word-processing (from MS-Word or Open Office), Spreadsheets, to databases and multimedia files (such as images, sounds and videos).

Kantor (2006) identified 3 aspects that define a document:


 * content
 * structure, and
 * style.

Not all documents will contain all three, for example a file containing a list of names and addresses to be used by another computer could have no style information. However, any document to be used for human interaction or display will have all three.

Document tree
The DOM can be thought of as a tree diagram constructed from the tags in an HTML page.

So a simple DOM for the web page is:

If you look closely at the example you can see that a form element can be referenced by navigating the DOM tree (document can be related to the body tag).
 * document.myForm.txtFname.value;

Another one you have come across is the document.write command where a line of text (usually html code) is inserted into the web page.

getElementById
In practice in Javascript we normally use getElementByID and provide the elements with an id attribute. So in the example above we can replace
 * alert("Hello " + strMessage);

with
 * document.getElementById('Msg').innerHTML = "Hello " + strMessage;

and the div tag contents will change on the form.

Resources

 * Koch, P.-P. (2007). JavaScript - W3C DOM - Introduction. Retrieved June 14, 2009 from http://www.quirksmode.org/dom/intro.html