: Understand the DOM
By the end of this page you will be able to:
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:
- structure, and
|aspect||Text document||HTML document|
|content||the information, or|
meta-information(properties e.g. author, table of contents, etc.)
|information: content in the <body>, |
meta:contained in the <head> tag
|structure||chapters, paragraphs, lists||Formatting tags such as: <p>,<div>, <li>|
|style||includes the fonts, colours, etc.||At top level can identify the output media, screen, printer, Braille, |
<link rel="stylesheet" ... media="print"> (w3c:Media types, n.d.)
to identifying how to display fonts, colours, backgrounds, etc. usually via the style attribute.
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.
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).
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.
- alert("Hello " + strMessage);
- document.getElementById('Msg').innerHTML = "Hello " + strMessage;
and the div tag contents will change on the form.
- Kantor, P. L. (2006). Peter L. Kantor - Lectures and References. Retrieved June 14, 2009 from http://www.daaq.net/index.php?path=reference/documents/
- w3c:Media types (n.d.) Media types. Retrieved June 14, 2009 from http://www.w3.org/TR/CSS2/media.html