English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM images attribute

HTML DOM Document Object

imagesA read-only attribute that returns the embedded<IMG>List of elements.

The elements in the list are sorted in the order they appear in the source code.

Syntax:

document.images
var x = document.images.length;
Test and see‹/›

Browser compatibility

All browsers fully support the images attribute:

Attribute
imagesIsIsIsIsIs

Property

AttributeDescription
lengthReturns in the list<img>Number of elements

Method

MethodDescription
[index]Returns the specific node at the given index starting from zero in the list. If the index number is out of range, it returns null.
item(index)Returns the specific node at the given index starting from zero in the list. If the index number is out of range, it returns null.
namedItem(id)Returns a specific node whose ID name matches the string specified by name. If the id does not exist, it returns null.

Technical Details

Return Value:OneHTMLCollectionProvides a live list of all images contained within the current file.
DOM Version:DOM Level1

More Examples

This example browses through an image list and finds an image named "flower.jpg":

var imgList = document.images;
for (let i = 0; i < imgList.length; i++) {
if (imgList[i].src.endsWith("flower.jpg")) {
   // found the flower
}
}
Test and see‹/›

HTML DOM Document Object