The first of the “traditional” JavaScript selectors, getElementsByTagName
does exactly what it says, creating an HTMLCollection
of elements from a web page. The result of the method is usually set to the value of a variable:

The first of the “traditional” JavaScript selectors, getElementsByTagName
does exactly what it says, creating an HTMLCollection
of elements from a web page. The result of the method is usually set to the value of a variable:
Just as document.getElementById
selects an element with a particular id
value, getElementsByClassName
gathers elements on a page that share a defined class
value. As the plural name of the method suggests, getElementsByClassName
collects an array of elements, never just one result… even if it matches only one element on the page.
One of the earliest and most fundamental means of referencing an element in JavaScript, getElementById
is very frequently used to “latch onto” an element for manipulation.