Chapter 14. The Document Object
Every Window object has a
document
property. This property refers to a Document object that represents
the HTML document displayed in the window. The Document object is
probably the most commonly used object in client-side JavaScript.
We’ve already seen several examples in this book that use the
write( )
method of the Document object to insert
dynamic content into a document while it is being parsed. In addition
to the frequently used write( )
method, the
Document object defines properties that provide information about the
document as a whole: its URL, its last-modified date, the URL of the
document that linked to it, the colors in which it is displayed, and
so on.
Client-side JavaScript exists to turn static HTML documents into
interactive programs -- it is the Document object that gives
JavaScript interactive access to the content of otherwise static
documents. In addition to the properties that provide information
about a document as a whole, the Document object has a number of very
important properties that provide information about document content.
The forms[]
array, for instance, contains Form objects that represent all the
HTML forms in the document. And the
images[]
and applets[]
arrays contain objects that represent the images and applets in the
document. These arrays and the objects they contain open up a world
of possibilities for client-side JavaScript programs, and the bulk of
this chapter is devoted to documenting them.
This chapter ...
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.