Back to Home

Walking the DOM

The DOM allows us to do anything with elements and their contents, but first we need to reach the corresponding DOM object. All operations on the DOM start with the document object. That’s the main “entry point” to DOM. From it we can access any node. Here’s a picture of links that allow for travel between DOM nodes: Let’s discuss them in more detail.

On top: documentElement and body

= document.documentElement

The topmost document node is document.documentElement. That’s the DOM node of the tag. = document.body

Another widely used DOM node is the element – document.body. = document.head

The tag is available as document.head.

Children: childNodes, firstChild, lastChild

There are two terms that we’ll use from now on: