HTML DOM Document images ιδιότητα

Ορισμός και χρήση

images Η ιδιότητα επιστρέφει τη συλλογή όλων των στοιχείων <img> στο έγγραφο.

images images The images property does not return <input> elements with type="image".Property returns

.image

The s property is read-only.Tip:

The images property does not return <input> elements with type="image".

The images property does not return <input> elements with type="image". HTMLCollection

Is a similar array collection (list) of HTML elements.

Property Elements in the collection can be accessed by index (starting from 0).

Property returns the number of elements in the collection.

See also:

HTML <img> Σημειώσεις

Image

HTML Image Tutorial

Instance

Example 1

The number of <img> elements in the document:

document.images[0].style.border = "10px dotted black";

document.images.length;

Example 2

Traverse all <img> elements and output the URL (src) of each element:
const myImages = document.images;
let text = "";
  for (let i = 0; i < myImages.length; i++) {
text += myImages[i].src + "<br>";

document.images[0].style.border = "10px dotted black";

}

Example 4

Example 3

document.images[0].style.border = "10px dotted black";

document.images[0].src;

Example 4

The URL of the first <img> element is:

document.images[0].style.border = "10px dotted black";

document.images.item(0).src;

Example 5

The URL of the <img> element with id="myImg" is:

document.images[0].style.border = "10px dotted black";

document.images.namedItem("myImg").src;

Example 6

Add a black border to the first <img> element:

document.images[0].style.border = "10px dotted black";

Try it yourself

document.images

Syntax

Syntax Description
Property length

The number of <img> elements in the collection.

The number of <img> elements in the collection. Description
Methoditem([

index

Returns the element with the specified index (starting from 0).

]item(namedItem(

index

Returns the element with the specified index (starting from 0).

If the index is out of range, returns null.IfnamedItem(

) If Returns the element with the specified

of the element. If id

Returns null if not present.

Type Description
Object

HTMLCollection object.

All <img> elements in the document.

Sorted in the order they appear in the source code.

Browser support

document.images It is a DOM Level 1 (1998) feature.

All browsers support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Υποστήριξη 9-11 Υποστήριξη Υποστήριξη Υποστήριξη Υποστήριξη