If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

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.

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:

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.

The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.

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)

The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.