DOM Level 2 - Example

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

DOM Level 2 - Published in November, 2000: An API of 14 modules: Core, XML, HTML, Views, StyleSheets, CSS, CSS2, Events, User interface Events, Mouse Events, Mutation Events, HTML Events, Range, and Traversal.

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

<!-- DOM_Level_2_Example.html
   Copyright (c) 2013 by Dr. Herong Yang,
<title>DOM Level 2 Example</title>
<style type="text/css">body {background-color: #aaaaff}</style>
<script type="text/javascript" id="myScript">
   var script = document.getElementById("myScript");
   document.writeln("   .toString()="+script.toString());

   var view = document.defaultView;
   document.writeln("   .toString()="+view.toString());
   document.writeln("   .document="+view.document.toString());
   var list = document.styleSheets;
   document.writeln("   .toString()="+list.toString());
   var style = list.item(0);
   document.writeln("   .item(0)="+style.toString());
   document.writeln("   .item(0).type="+style.type);
   document.writeln("   .item(0).ownerNode="+style.ownerNode);


View this JavaScript example page in Firefox 2.0, which supports DOM Level 2, you will get:

   .toString()=[object HTMLScriptElement]

   .toString()=[object Window]
   .document=[object HTMLDocument]

   .toString()=[object StyleSheetList]
   .item(0)=[object CSSStyleSheet]
   .item(0).ownerNode=[object HTMLStyleElement][object CSSStyleDeclaration]

This JavaScript example page will not work in IE 6.0, because it does not support DOM Level 2.

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


 PDF Printing Version