HTML DOM Belgesi görüntüleri
Örnek
Belgedeki <img> öğelerinin sayısı:
document.images.length;
Tüm <img> öğeleri üzerinde dolaşın ve her birinin URL'sini (src) çıktılayın:
const myImages = document.images;
let text = "";
for (let i = 0; i < myImages.length; i++) {
text += myImages[i].src + "<br>";
}
İlk <img> öğesinin URL'si:
document.images[0].src;
İlk <img> öğesinin URL'si:
document.images.item(0).src;
Aşağıda daha fazla örnek.
Tanım ve Kullanım
Özellik images
, bir belgedeki tüm <img> öğelerinin bir koleksiyonunu döndürür.
Özellik images
, bir HTMLCollection döndürür .
images
Mülk salt okunurdur .
Not
Özellik images
, type="image" ile <input> öğelerini döndürmez.
Ayrıca bakınız:
HTML Koleksiyonu
HTMLCollection , HTML düğümlerinin bir koleksiyonudur .
Bir koleksiyondaki düğümlere dizin numaralarıyla erişilebilir. Endeks 0'dan başlar.
Uzunluk Özelliği , koleksiyondaki öğelerin sayısını döndürür.
Sözdizimi
document.images
Özellikler
Property | Description |
length | The number of <img> elements in the collection. |
yöntemler
Method | Description |
[index] | Returns the element with the specified index (starts at 0). Returns null if the index is out of range. |
item(index) | Returns the element with the specified index (starts at 0). Returns null if the index is out of range. |
namedItem(id) | Returns the element with the specified id. Returns null if the id does not exist. |
Geri dönüş değeri
Tip | Açıklama |
Nesne | Bir HTMLCollection Nesnesi. Belgedeki tüm <img> öğeleri. Öğeler, belgede göründükleri gibi sıralanır. |
Daha fazla örnek
id="myImg" içeren <img> öğesinin URL'si:
document.images.namedItem("myImg").src;
İlk <img> öğesine siyah bir kenarlık ekleyin:
document.images[0].style.border = "10px dotted black";
Tarayıcı Desteği
document.images
bir DOM Düzey 1 (1998) özelliğidir.
Tüm tarayıcılarda tam olarak desteklenir:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |