Sams Teach Yourself JavaScript in 24 Hours

Sams Teach Yourself JavaScript in 24 Hours

By Michael Moncur

Working with DOM Nodes

As you learned in Hour 19, "Using Dynamic HTML (DHTML)," the DOM organizes objects within a Web page into a tree-like structure. Each node (object) in this tree can be accessed in JavaScript. In the next sections you will learn how you can use the properties and methods of nodes to manage them.

Basic Node Properties

You have already used the style property of nodes to change their stylesheet values. Each node also has a number of basic properties that you can examine or set. These include the following:

Node Relationship Properties

In addition to the basic properties described above, each node has a number of properties that describe its relation to other nodes. These include the following:

Document Methods

The document node itself has several methods you may find useful. You have already used one of these, getElementById, to refer to DOM objects by their ID properties. The document node's methods include the following:

Node Methods

Each node within a page has a number of methods available. Which of these are valid depends on the node's position in the page, and whether it has parent or child nodes. These include the following:

Share ThisShare This

Informit Network