HTML DOM Attributes length property
- Halaman sebelumnya item()
- Halaman berikutnya name
- Kembali ke tingkat tinggi Atribut DOM HTML
Definition and usage
length
The attribute returns the number of nodes in NamedNodeMap.
length
Attributes are read-only.
Note:The attributes of an HTML element 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, representing the number of attribute nodes in nodemap.
browser support
attributes.length
Adalah ciri DOM Level 1 (1998).
Semua pelayar mendukungnya:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Dukungan | 9-11 | Dukungan | Dukungan | Dukungan | Dukungan |
- Halaman sebelumnya item()
- Halaman berikutnya name
- Kembali ke tingkat tinggi Atribut DOM HTML