HTML DOM Element attributes property
- အဆင်းချိုးပြင်း appendChild()
- နောက်ပိုင်း blur()
- အဆင်းချိုးအပြင်း HTML DOM Elements အကို
Definition and usage
attributes
attribute returns a collection of attributes within an element.
attributes
attribute returns NamedNodeMap.
NamedNodeMap
NamedNodeMap an unordered collection of element attributes similar to an array.
In other words: NamedNodeMap is Attr object.
NamedNodeMap provides a list that can return the number of nodes. length property.
Nodes can be accessed by name or index (subscript). The index starts from 0.
Please see also:
Instance
Example 1
<img> element has how many attributes:
let numb = document.getElementById("myImg").attributes.length;
ကျွန်ုပ်ကိုယ်ဖြင့် ကြိုးစားလမ်းမေးမြန်းပါ။
Example 2
Show all attributes of <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;
ကျွန်ုပ်ကိုယ်ဖြင့် ကြိုးစားလမ်းမေးမြန်းပါ။
အမှတ် 3 သဘောတူ
<button> အခြေခံအရာအများစုအား အခြေခံအရာများ၏ အရေအတွက်ကို သိပါသည်:
let numb = document.getElementById("myButton").attributes.length;
ကျွန်ုပ်ကိုယ်ဖြင့် ကြိုးစားလမ်းမေးမြန်းပါ။
အမှတ် 4 သဘောတူ
Get the name of a <button> element's second (index 1) attribute:
let attr = document.getElementById("myBtn").attributes[1].name;
အဓိပ္ပာယ်
node.attributes
အပြန်ရလဒ်
အမျိုးအစား | ဖော်ပြ |
---|---|
NamedNodeMap | အခြေခံအရာပါဝင်သော အခြေခံအရာများ၏ စုအမှုန်း။ |
ဘရူးတီးနားဆက်သွယ်မှု
element.attributes
သည် DOM Level 1 (1998) အခြေခံအရာဖြစ်သည်။
အားလုံး ဘရာဇက်ပြာ အတိုင်း အောင်မြင်စွာ ထောက်ပံ့ပေးသည်
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
ထောက်ပံ့ | 9-11 | ထောက်ပံ့ | ထောက်ပံ့ | ထောက်ပံ့ | ထောက်ပံ့ |
- အဆင်းချိုးပြင်း appendChild()
- နောက်ပိုင်း blur()
- အဆင်းချိုးအပြင်း HTML DOM Elements အကို