1. According to W3C standards, attributes is an unordered collection of attributes, not an array, thus, in theory, attributes has no length.
2. Unfortunately, the implementation of attributes is buggy in all the browsers. Some browsers take it as an array, some don't. Older versions of IE do not consider style or events as attributes (corrected partially in IE9). IE7 counts all the possible attributes, not only the effectively set.
There are many reasons for attributes is not cross-browser trusty.
What, in fact, is your final aim? What do you rally want to do?
1. According to W3C standards, attributes is an unordered collection of attributes, not an array, thus, in theory, attributes has no length.
just because it’s not an array doesn’t mean it doesn’t have a length. according to the DOM specs, a NamedNodeMap (the attribute list) does have a length*.
* - from the specs:
Quote:
Objects contained in an object implementing NamedNodeMap may also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of a NamedNodeMap, and does not imply that the DOM specifies an order to these Nodes.
__________________
please post your code wrapped in [CODE] [/CODE] tags
just because it’s not an array doesn’t mean it doesn’t have a length. according to the DOM specs, a NamedNodeMap (the attribute list) does have a length*.
* - from the specs:
Could be. But some browsers simply don't take it at all as an array. . Maybe I was confused in my previous post. attributes should return a collection, right. A collection can be treated as an array, except from some array methods. The problem is that is some browsers it looks like attributes is implemented like an object, which make this property to lose its length.
DOM list (i.e. NodeList & NamedNodeMap) are never and never have been arrays, that’s a common misconception. thus they don’t even have a single array method. and to the best of my knowledge, no browser has ever treated DOM lists as an array, they’re just too different. (e.g. DOM lists are live)
__________________
please post your code wrapped in [CODE] [/CODE] tags