nutso said:
I used array generically:
Fine, but the result is that some people reading it think "array" means
javascript Array. It is similar to the argument about Objects and
associative arrays.
[...]
So, what does namedItem(radiobuttons') refer to, the same collection from
which you derived it? That certainly is what occurs with dot notation, where
you can append dot names til bulls fly and you're still looking at the same
collection. Doesn't strike me as very logical behavior.
Regardless, your logic isn't proof that the object in question isn't an
HTMLCollection.
Try same-naming mixed radio and input checkbox types and see what happens.
Check a checkbox, then check an unchecked radio button. Which is more
logical, IE or FF?
I don't understand how that is relevant.
The original point of contention was whether the existence of a
namedItem method can be used as an indicator of whether or not the
object in question was an HTMLCollection. The fact that at least one
browser does implement the method supports the contention that it is.
When combined with the other observed behaviour, and relevant sections
of the W3C spec, the evidence is very strong that it is an
HTMLCollection. The fact that some other browser doesn't implement a
namedItem method is not proof that it isn't. That factor is weakened
when you consider that that browser also doesn't implement the method
on an object that clearly should have it according to the W3C spec.
I hope that makes sense.
Firefox doesn't implement the namedItem method for forms either, but I
don't think you'd deduce from that that a form isn't a dinky-di
HTMLForm.
From what I've grokked of the DOM, I think dot notation and nodelist[n]
indexing should be defined as shortcuts for namedItem and index methods,
i.e. .namedItem('name') == .name and list.item(n) == list[n]. Then it could
be said that FF implements the shortcut form of namedItem method.
All that can be inferred from that is Firefox (et al) implements
javascript dot property access to DOM HTMLElement object properties
(Firefox often restricts such access to only those attributes that are
specified in the relevant DTD and requires the use of getAttribute to
access other (non-standard) attributes).
I don't understand why, given two inputs named "input1" in form1,
document.forms.form1.input1[0].value
refers to the value property of the first, while, given two images named
"image1",
document.images.image1[0].src
throws an exception.
I suspect for backward compatibility. The original syntax (i.e. circa
Navigator 3) would have been:
document.image1[0].src;
which "works" in IE and Firefox (and is consistent with the access
scheme for form elements noted previously) but it assumes prior
knowledge that document.image1 will return a collection, otherwise
you'll get an error.
It is usually handled by something like:
var x = document.image1;
if ( typeof x.length == 'number' ){
/* got back a collection */
} else {
/* got back a single node */
}
It seems that with the introduction of a standardised DOM, support for
the old method was retained for backward compatibility and that new
syntax was introduced to use IDs and more explicitly address
collections, so that:
document.images
returns the collection and
document.images.<imageName_or_ID>
returns some member of that collection. It does seem inconsistent that
in this particular case, the name attribute behaves like an ID and only
returns a single node (in IE and Firefox at least) - there is probably
an old timer lurking who has an opinion about that.
Is there an explanation in the DOM spec of why
like-named form elements are a collection but like-named elements in other
HTMLCollections are not?
Not that I'm aware of - the behaviour you describe is browser specific.
In the above scenario and given:
var docImages = document.images;
docImages.namedItem('image1') returns a single element in Firefox, but
IE returns a collection of the like-named img elements. That seems
consistent with the behaviour of each browsers' implemenation of form
control collections.
Variations in the implementation of (and outright non-compliance with)
W3C standards is hardly uncommon. There is also a very wide range of
non-specified behaviours (e.g. DOM 0), so all that can be said is that
where compliance is claimed, things *should* behave as per the spec -
but expect that in reality they sometimes don't or wont and deal with
it (I'm sure Randy Webb is itching to make a comment about that ;-) ).