HTML DOM Element attributes attribute
- Previous Page appendChild()
- Next Page blur()
- Bumalik sa Ngaunang Pahina HTML DOM Elements Obheto
Definition and Usage
attributes
Attribute ay nagbibigay ng collection ng mga attribute sa element.
attributes
Attribute ay nagbibigay ng NamedNodeMap.
NamedNodeMap
NamedNodeMap ay isang di-ayos na collection na katulad ng array ng mga element property.
Sinasabi nang ibang paraan: Ang NamedNodeMap ay Attr object.
NamedNodeMap ay nagbibigay ng listang maaaring makuha ang bilang ng mga node. Length attribute.
Maaaring ma-access ang mga node sa pamamagitan ng pangalan o index number (subscript). Ang index ay nagsisimula sa 0.
Para malaman pa:
Example
Example 1
How many attributes does an <img> element have:
let numb = document.getElementById("myImg").attributes.length;
Example 2
Display all attributes of an <img> element:
const nodeMap = document.getElementById("myImg").attributes; let text = ""; for (let i = 0; i < nodeMap.length; i++) { text += nodeMap[i].name + " = " + nodeMap[i].value + "<br>"; } document.getElementById("demo").innerHTML = text;
Example 3
How many attributes does a <button> element have:
let numb = document.getElementById("myButton").attributes.length;
Example 4
Get the name of a <button> element's second (index 1) attribute:
let attr = document.getElementById("myBtn").attributes[1].name;
Syntax
node.attributes
Return value
Type | Description |
---|---|
NamedNodeMap | A collection ng mga attribute object. |
Suporta ng browser
element.attributes
Ang ay DOM Level 1 (1998) na katangian.
Lahat ng mga browser ay ganap na sumusuporta dito:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous Page appendChild()
- Next Page blur()
- Bumalik sa Ngaunang Pahina HTML DOM Elements Obheto