HTML and CSS Reference
"hot" + "dog" or "San Francisco" + "<br />"
For more information on strings, see Chapter 3, “The Building Blocks: Data Types,
Literals, and Variables.”
pages dynamically. Data, text, and HTML itself can be written to the browser on the fly.
HTML to the document as it is being parsed. When generating output with write() and
writeln() , put the text in the body of the document (rather than in the header) at the
place where you want the text to appear when the page is loaded.
Method names are followed by a set of parentheses. They are used to hold the argu-
ments. These are messages that will be sent to the methods, such as a string of text, the
output of a function, or the results of a calculation. Without arguments, the write() and
writeln() methods would have nothing to write.
as a document object. (You will learn more about objects later.) For now, whenever you
refer to the document object, the object name is appended with a dot and the name of
the method that will manipulate the document object. In the following example the
write( ) method must be prepended with the name of the document object and a period.
The browser will display this text in the document's window. The syntax is
document.write("Hello to you");
The writeln() method is essentially just like the write() method, except when the text
is inserted within HTML <pre> or <xmp> tags, in which case writeln() will insert a new-
line at the end of the string. The HTML <pre> tag is used to enclose preformatted text.
It results in “what you see is what you get.” All spaces and line breaks are rendered lit-
erally, in a monopitch typeface. The <xmp> tag is an obsolete HTML tag that functions
much like the <pre> tag.
<body bgcolor="yellow" text="blue">
<b>Comparing the <em>document.write</em> and
<em>document.writeln</em> methods</b><br />
document.write("One, "); // No newline