DOM HTML Koleksiyonu
HTMLCollection Nesnesi
HTMLCollection nesnesi, HTML öğelerinin dizi benzeri bir listesidir.
getElementsByTagName() gibi yöntemler bir HTMLCollection döndürür.
Özellikler ve Yöntemler
Bir HTMLCollection nesnesinde aşağıdaki özellikler ve yöntemler kullanılabilir:
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 |
Örnekler
Örnek
Bir HTMLCollection alın:
var x = document.getElementsByTagName("P");
// Returns a
collection of all the P elements in the document
Örnek
Belgedeki <p> öğelerinin sayısını yazın:
var x = document.getElementsByTagName("P");
document.write(x.length);
Örnek
Bir HTMLCollection'daki her öğe arasında dolaşın:
x = document.getElementsByTagName("*");
l = x.length;
for (i = 0; i <
l; i++) {
document.write(x[i].tagName + "<br>");
}