kk said:
What is returned when you retrieve dom elements from getElementById?
^
Reasonably, you can't. As the name says, get*Element*ById() returns a
reference to *one* element object (a true-value) if there is such an
element, `null' (that is, a false-value) if there is none, or an
unspecified value if there are more than one matching element (the
underlying document would likely be invalid then).
My instructor says its an array.
Either they are mistaken or you have misunderstood what they were saying.
It is possible to access members of this data using an index like arrays
ISTM you are confusing this with HTMLDocument::getElement*s*ByName(), and
Document::getElement*s*ByTagName() and its namespace-aware variant.
but I say its not exactly right to call it an array since javascript has
an array() object as part of it api.
There is no "javascript" as a single language, there are more or less
conforming implementations of the ECMAScript Language Specification.
<
http://PointedEars.de/es-matrix>
ECMAScript implementations do not have an API, they are programming
languages. The W3C DOM, on the other hand, *is* a API that can be used
with ECMAScript implementations, among other programming languages.
Arrays as a data structure are encapsulated in ECMAScript implementations by
*Array* objects, named for their constructor. Those programming languages
are *case-sensitive*.
The two methods I mentioned above return a reference to an object that
implements the NodeList interface (short here: a NodeList object), not to
an Array object. The former object has an item() method that can be
triggered in ECMAScript implementations by using the square bracket
property accessor notation and a numeric parameter. For example, if `n'
refers to a NodeList object and it has at least one item, you can refer to
the first item by `n[0]'. (That is probably what you mean with "like
arrays". However, in ES implementations, this notation works for every
object, not only Array objects.)
RTFM:
<
http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document>
<
http://www.w3.org/TR/DOM-Level-3-Core/ecma-script-binding.html>
<
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268>
<
http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>
PointedEars