The Docoment Object Model (DOM) defines interfaces for programmatically accessing and manipulating the elements of a (typically HTML or SVG) document.

The DOM interfaces are available in JavaScript in the form of a large set of built-in objects with specific properties and methods.

Web Development Pitfall No.1: Confusing a DOM collection with a JS array

gwagner's picture


Don't confuse a DOM collection with a JS array: Array functions, such as the forEach looping method, cannot be applied to a DOM collection!

For instance, when you retrieve all rows of an HTML table element, you get an HTMLCollection, which is an array-like object, but not an instance of Array, and therefore the following code does not succeed because the Array method forEach is not defined for an HTMLCollection like myTableEl.rows:

Subscribe to RSS - DOM