Chapter 15. Scripting Documents
Client-side JavaScript exists to turn static HTML documents into interactive web applications. Scripting the content of web pages is the central purpose of JavaScript. This chapter—one of the most important in the book—explains how to do this.
Chapters 13 and 14 explained that every web browser
window, tab, and frame is represented by a Window object. Every Window
object has a document property that
refers to a Document object. The Document object represents the content
of the window, and it is the subject of this chapter. The Document
object does not stand alone, however. It is the central object in a
larger API, known as the Document Object
Model , or DOM, for representing and manipulating
document content.
This chapter begins by explaining the basic architecture of the DOM. It then moves on to explain:
How to query or select individual elements from a document.
How to traverse a document as a tree of nodes, and how to find the ancestors, siblings, and descendants of any document element.
How to query and set the attributes of document elements.
How to query, set, and modify the content of a document.
How to modify the structure of a document by creating, inserting, and deleting nodes.
How to work with HTML forms.
The final section of the chapter covers miscellaneous document
features, including the referrer
property, the write() method, and
techniques for querying the currently selected document text.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access