Array versus Collection
This page previously referred to the attributes property returning an array, however that is misleading. It returns a collection which is an object that has a length property and the attributes are accessible by numeric index. However, collections do not have any of the special properties of an Array object.
--RobG 18:25, 30 December 2005 (PST)
As incredible as it may seem, yesterday I modified the attributes article without knowing/reading what was in the Talk section and I had achieved the same conclusion you had, RobG.
Overall, the vocabulary used in the Gecko Reference should be checked more closely, more correct technically speaking... otherwise people will be confused, will be mislead or will misunderstand concepts and eventually the DOM specs we are trying to explain/to document.
--GT 19:33, 16 January 2006 (EST)
- attributes returns a collection of the specified attributes of the given element.
Doesn't it just return all attributes? --Nickolay 15:09, 16 January 2006 (PST)
Nickolay, no, it does not in the code I tried in Firefox 1.5 and Opera 9 beta 1. It will return all attributes specified in the markup code but none that are implicit. E.g.:
The only attribute returned in the attributes collection will be the id attribute but it will not return the common attributes (or others); e.g. say, the lang attribute even though the markup code (<html lang="en">) may have defined the lang for that <p id="abc">. Also, I tested objReference.attributes.length in 3 browsers. MSIE 6 will return all attributes, even those not explicitly defined; Firefox 1.5 and Opera 9 beta 1 will only return specified attributes. So, here, there is a major browser divergence and the spec should clarify, untangle the issue. DOM 2 Core and DOM 3 Core do not clarify that issue.
I checked Bugzilla database and found nothing on this; I checked quirksmode.org and got:
"(...) x.attributes Explorer puts its entire list of possible attributes in the attributes array (84 in IE 6.0 Win!) The list of attributes is alphabetical in Explorer 5, non-alphabetical in 6. Explorer Mac doesn't put custom attributes in the list.
According to all other browsers this means the second actual attribute of node x, decidedly the saner interpretation." http://www.quirksmode.org/dom/w3c_co...tml#attributes
Interestingly, getAttribute and getAttributeNode may/might be returning (will return?) the value of non-specified ones. I have not tested this.
Whatever the truth might be, I think we should report browser differences when they are meaningful to the property or method defined. --GT 19:09, 16 January 2006 (EST)