The Document Object Model (DOM)

The document object is an object created automatically by the browser for each new HTML page that is viewed and you can access a number of properties and methods that can affect the document which are very useful when writing scripts.

The Document Object Model (DOM) allows JavaScript to access the structure of the document in the browser. Each HTML document is made of structured nodes. For example the body tag is a node and any element within the body will be a child node of the body element. Of course, each child node can have its own nodes too.

<h1>Nodes and child nodes</h1>
<img src="myimage.jpg" alt="My Image" />

The body element is a node. It has two child nodes: the h1 element and the img element. The h1 contains a text node as its child node. The img element contains two attribute nodes: src="myimage.jpg" and alt="My Image".

Accessing the DOM allows you to create more dynamic pages. You can also create elements and nodes using certain JavaScript methods of the document object.

Leave a Reply