title | short-title | slug | l10n | ||
---|---|---|---|---|---|
Document: images プロパティ |
images |
Web/API/Document/images |
|
{{APIRef("DOM")}}
images
は {{domxref("Document")}} インターフェイスの読み取り専用プロパティで、現在の HTML 文書内の画像の集合を返します。
現在の文書内に掲載されているすべての画像の生きたリストを提供する {{domxref("HTMLCollection")}} 。 集合の各項目は、単一の画像要素を表す {{domxref("HTMLImageElement")}} です。
返された集合において、集合内のアイテムにアクセスするには、JavaScript の配列記法か {{domxref("HTMLCollection.item", "item()")}} メソッドを使用することができます。 以下はのものは同等です。
firstImage = imageCollection.item(0);
firstImage = imageCollection[0];
この例では、画像のリストを見て、"banner.gif"
という名前の画像を探します。
for (const image of document.images) {
if (image.src === "banner.gif") {
console.log("バナーを見つけました");
}
}
{{Specifications}}
{{Compat}}