HTML DOM Attributes length property
- Previous page item()
- Next page name
- Go back to the previous level HTML DOM Attributes
definition and usage
length
the attribute returns the number of nodes in the NamedNodeMap.
length
attributes are read-only.
note:attributes of HTML elements are located in NamedNodeMap.
see also:
instance
example 1
get the number of attributes of an HTML element:
let num x = document.getElementById("myButton").attributes.length;
example 2
get all attribute names:
const nodeMap = document.getElementById("myButton").attributes; let text = ""; for (let i = 0; i < nodeMap.length; i++) { text += nodeMap[i].name + "<br>"; }
example 3
how many attributes does "myImg" have:
let num = document.getElementById("myImg").attributes.length;
example 4
get all attributes:
const nodeMap = document.getElementById("myImg").attributes; let text = ""; for (let i = 0; i < nodeMap.length; i++) { text += nodeMap[i].name + " = " + nodeMap[i].value + "<br>"; }
syntax
namednodemap.length
technical details
return value
number, indicating the number of attribute nodes in the nodemap.
browser support
attributes.length
Is DOM Level 1 (1998) feature.
All browsers support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous page item()
- Next page name
- Go back to the previous level HTML DOM Attributes