DOM API - The "document" Object

This section provides a quick description of the 'document' object of the DOM API. A tutorial example is provided on building a simple HTML document with the 'document' object.

A typical Web browser provides the DOM (Document Object Model) API (Application Programming Interface) to allow JavaScript codes to interact with the browser and the HTML document.

The most commonly used object in the DOM API is the "document" object, which has the following features:

To illustrate some nice features of the "document" object, I wrote this JavaScript tutorial example:

<html>
<!-- Document_Object.html
   Copyright (c) 2008 HerongYang.com. All Rights Reserved.
-->
<head>
<title>Document Object</title>
<script type="text/javascript">
function buildDocument() {
   // Building a <p> tag
   var paragraph = document.createElement("p");
   var text = document.createTextNode("Hello World!");
   paragraph.appendChild(text);

   // Inserting the <p> tag
   document.body.appendChild(paragraph);
   document.body.bgColor = "lightblue";
}
</script>
</head>
<body onLoad="buildDocument();"/>
</html>

If you run this JavaScript page in a browser, you will see the "Hello World!" paragraph with light blue background.

For more tutorial examples on the "document" object, see the DOM API chapters in this book.

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

 JavaScript Support in Web Browsers

 Including JavaScript Codes with HTML "script" Tags

 type="text/javascript" or language="JavaScript"

 JavaScript Version Supported by Browsers

 Including 'script' Tags in String Literals

 Escaping 'script' Tags in String Literals

 Using HTML Entities to Protect HTML Tags

 Including JavaScript Codes as External Files

DOM API - The "document" Object

 DOM API - The "window" Object

 DOM API - The "window.open" Method

 Event Listeners and Objects

 'javascript:' Pseudo-URL Addresses

 JavaScript Console in Google Chrome

 JavaScript Console in Mozilla Firefox

 JavaScript Console in Apple Safari

 JavaScript Console in IE (Internet Explorer)

 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

 AJAX (Asynchronous JavaScript And XML)

 References

 Full Version in PDF/EPUB