images
Summary
Legacy method. Use document.querySelectorAll(“img”) instead. Gets a live collection of img elements in a document.
Property of dom/Documentdom/Document
Syntax
Note: This property is read-only.
var imageCollection = document.images;
Return Value
Returns an object of type
A live collection of img elements in the document.
Examples
Logging the source URL of the first image in the document using the legacy property.
// Caching the collection,
// instead of looking up the images property every time.
// Alternatively and more efficiently,
// use document.querySelectorAll("img") here instead.
var imageList = document.images;
// Verifying the collection is not empty.
if (imageList.length) {
console.log(
"The source URL of the first image in the document is - " +
// Getting the src property of the first item in the collection.
imageList[0].src);
}
Usage
This is a legacy property. Use document.querySelectorAll("img") instead, which returns a static list instead.
Use this property to get a live collection of img elements in a document.
Notes
Since this property returns a live collection, there are performance implications.
Related specifications
- WHATWG HTML
- Living Standard
- HTML5
- Last Call Working Draft
Attributions
Microsoft Developer Network: [Windows Internet Explorer API reference Article]