When selecting elements on a web page there are various ways that you can do this.
An HTMLCollection object is an array-like list (collection) of HTML elements. (pseudo array)
The getElementsByTagName() method returns an HTMLCollection object.
An Array or not
The returned information from an HTML Collection Object is in the form of "collection" which can be interegated in a similar way to an array. This means that the "collection" can be traversed over its length and the information extracted from the "collection".
I have used this technique, reasonably successfully, to extract references to elements on a web page.
var acc = document.getElementsByClassName("accordion");
retrieves the "collection" of elements with the name "accordion"
In this particular instance the variable (a collection) is traversed and eventListeners are added (this need to be looked more!)
- "Getting" a page Element - methods to return elements
- getElement and getElements - Singular vs. Collection
- document.querySelectorAll - this probably the most powerful method
HTML Collections - January 2021