DOM HTMLCollection
HTMLCollection Object
HTMLCollection object သည် HTML ဒြပ်စင်များ၏ array-like list တစ်ခုဖြစ်သည်။
getElementsByTagName() ကဲ့သို့သော နည်းလမ်းများသည် HTMLCollection တစ်ခုကို ပြန်ပေးသည်။
ဂုဏ်သတ္တိများနှင့်နည်းလမ်းများ
HTMLCollection object တစ်ခုတွင် အောက်ပါဂုဏ်သတ္တိများနှင့် နည်းလမ်းများကို အသုံးပြုနိုင်ပါသည်။
Property / Method | Description |
---|---|
item() | Returns the element at the specified index in an HTMLCollection |
length | Returns the number of elements in an HTMLCollection |
namedItem() | Returns the element with the specified ID, or name, in an HTMLCollection |
ဥပမာများ
ဥပမာ
HTML စုဆောင်းမှုကို ရယူပါ-
var x = document.getElementsByTagName("P");
// Returns a
collection of all the P elements in the document
ဥပမာ
စာရွက်စာတမ်းတွင် <p> ဒြပ်စင်အရေအတွက်ကို ရေးပါ-
var x = document.getElementsByTagName("P");
document.write(x.length);
ဥပမာ
HTMLCollection တစ်ခုရှိ အစိတ်အပိုင်းတိုင်းကို လှည့်ပတ်ကြည့်ပါ-
x = document.getElementsByTagName("*");
l = x.length;
for (i = 0; i <
l; i++) {
document.write(x[i].tagName + "<br>");
}