HTML DOM Attributes length property
- Προηγούμενη σελίδα item()
- Επόμενη σελίδα name
- Επιστροφή στο προηγούμενο επίπεδο HTML DOM Attributes
definition and usage
length
the attribute returns the number of nodes in the NamedNodeMap.
length
attributes are read-only.
note:The attributes of an HTML element are located in the 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, representing the number of attribute nodes in the nodemap.
browser support
attributes.length
Είναι χαρακτηριστικά DOM Level 1 (1998).
Όλοι οι περιηγητές υποστηρίζουν το:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Υποστήριξη | 9-11 | Υποστήριξη | Υποστήριξη | Υποστήριξη | Υποστήριξη |
- Προηγούμενη σελίδα item()
- Επόμενη σελίδα name
- Επιστροφή στο προηγούμενο επίπεδο HTML DOM Attributes