Get the number of attributes of a <button> element:
The result of x could be:
More "Try it Yourself" examples below.
The length property returns the number of nodes in a NamedNodeMap object.
A Node object's attributes is an example of a NamedNodeMap object.
This property is read-only.
Tip: Use the item() method to return a node at the specified index in a NamedNodeMap object.
Property | |||||
---|---|---|---|---|---|
length | Yes | Yes | Yes | Yes | Yes |
Note: In Internet Explorer 8 and earlier, the length property for attributes will return the number of all possible attributes for an element.
Return Value: | A Number, representing the number of attribute nodes in the nodemap |
---|---|
DOM Version | Core Level 1 |
Loop through all attributes of a <button> element and output the name of each attribute:
The result of txt will be:
Find out how many attributes an <img> element have:
The result of x will be:
Loop through all attributes of an <img> element and output each attribute's name and value: