Coding with JavaScript For Dummies
Book image
Explore Book Buy On Amazon

HTML DOM trees resemble family trees in the hierarchical relationship between nodes. In fact, the technical terms used by JavaScript programmers to describe relationships between nodes in a tree take their names from familial relationships.

  • Every node, except the root node, has one parent.

  • Each node may have any number of children.

  • Nodes with the same parent are siblings.

Because HTML documents often have multiple elements that are of the same type, the DOM allows you to access distinct elements in a node list using an index number. For example, you can refer to the first

element in a document as p[0], and the second

element node as p[1].

Although a node list may look like an array, it’s not. You can loop through the contents of a node list, but you can’t use array methods on node lists.

In this code, the three

elements are all children of the

element. Because they have the same parent, they are siblings.

 The HTML Family


About This Article

This article is from the book:

About the book authors:

Chris Minnick is an accomplished author, trainer, and web developer who has worked on web and mobile projects for both small and major businesses. Eva Holland is an experienced writer and trainer who has designed and taught online, in-person, and video courses. They are cofounders of WatzThis?

This article can be found in the category: