The document.write() Method

This section provides a quick description of the document.write() method and a simple tutorial example of using the document.write() method.

As can see from the sample JavaScript in the previous section, the "document.write(string)" method is a very useful method. Here are some notes about this method:

You can use the "document.write(string)" method to write anything, including HTML tags, into the HTML document.

Here is a tutorial example that shows you how to use the document.write() method to write a large section of a HTML document:

<html>
<!-- Document_Write.html
   Copyright (c) 2013 by Dr. Herong Yang, herongyang.com
-->
<head><title>The document.write() Method</title></head>
<body>
<script type="text/javascript">
   document.write('<center>');
   document.write('Summer summer oh so hot,<br/>');
   document.write('Summer summer trapped in a pot.<br/>');
   document.write('When I open the lid I let you out,<br/>');
   document.write('You make me so happy<br/>');
   document.write('I want to shout!<br/>');
   document.write('</center>');
</script>
</body>
</html>

Table of Contents

 About This Book

Introduction to JavaScript

 What Is JavaScript?

 First JavaScript - "Hello World!"

 Walking through the First JavaScript

The document.write() Method

 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

 References

 PDF Printing Version