DOM Level 1 - Example

This section provides a tutorial example of DOM Level 1 objects and attributes that are supported in Firefox 2.0.

DOM Level 1 - Latest version published in October, 1998: An API of 2 modules: Core and HTML. DOM Level 1 Core represents the functionality used for XML documents. DOM Level 1 HTML extends DOM Level 1 Core to represents functionality specific to HTML documents.

Here is a tutorial example of using DOM Level 1 objects and properties:

<html>
<!-- DOM_Level_1_Example.html
   Copyright (c) 2013 by Dr. Herong Yang, herongyang.com
-->
<head>
<title>DOM Level 1 Example</title>
<script type="text/javascript">
var colorID = 0;
function changeColor() {
   var body = document.body;
   if (colorID == 0 )
      body.bgColor = "#ff8888";
   else if (colorID == 1 )
      body.bgColor = "#88ff88";
   else if (colorID == 2 )
      body.bgColor = "#8888ff";
   else if (colorID == 3 )
      body.bgColor = "#888888";
   document.forms.item(0).elements.item(0).value 
      = document.body.bgColor;
   colorID = (colorID+1)%4;
}
</script>
</head>
<body color="#000000">
<pre>
<script type="text/javascript">
   var body = document.body;
   document.writeln("\"documnet.body\" attribute initial values:");
   document.writeln("   aLink = "+body.aLink);
   document.writeln("   background = "+body.background);
   document.writeln("   bgColor = "+body.bgColor);
   document.writeln("   color = "+body.color);
   document.writeln("   link = "+body.link);
   document.writeln("   vLink = "+body.vLink);
</script>
</pre>
<form>
  Current document.body.bgColor: 
  <input type="text" name="bgcolor" value="#ffffff"><br/>
  <input type="button" value="Click to change background color"
   onClick="changeColor();"/>
</form>
</body>
</html>

Here is how this JavaScript page will look like on Firefox 2.0:
DOM Level 0 Example

It is interesting to see that document.body.color is undefined in Firefox 2.0. My guess is that document.body.color in supported in only in DOM HTML Level 1, not in Level 2. Since Firefox is supporting DOM HTML Level 2, document.body.color is undefined.

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

 Introduction to Built-in Object Types

W3C's Document Object Model (DOM) Specifications

 Overview of DOM Specifications

 DOM Level 0 - Example

DOM Level 1 - Example

 DOM Level 2 - Example

 DOM Level 3 - Example

 DOM Level Test - document.implementation.hasFeature

 Inheritance vs. Flattened Views of the API

 A Web Document as A Tree of Different Interfaces

 A Web Document as A Tree of Nodes

 Dump Document in a New Window - JavaScript Source

 Dump Document in a New Window - Firefox 2.0 Result

 Dump Document in a New Window - IE 6.0 Result

 References

 PDF Printing Version