The Document Object Model (DOM) is a hierarchical representation of an HTML document, which is available to JavaScript running in a browser. The DOM describes a web page as a tree of nodes which can themselves contain other nodes. A document’s html node contains a head node and abody. In turn, each contains its own set of nodes, and so on.

A useful operation on such a structure involves visiting each node in order. For example, to catalogue the HTML elements a page uses, we can visit each node in turn, keeping track of elements we encounter.

In this article, I’ll present two approaches to this general problem. They both use the following properties of the DOM Node interface:

#programming #dom #javascript #web-development

Two ways to visit every node in a web page using JavaScript
1.90 GEEK