HTML DOM imagesコレクション
Document オブジェクト
定義と使用法
images コレクションは、現在のドキュメント内のすべての画像の配列を返します。
構文
document.images[].property
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザが images コレクションをサポートしています
例
例 1
ドキュメントの画像数を返す:
<html>
<body>
<img border="0" src="klematis.jpg.html" width="150" height="113">
<img border="0" src="klematis2.jpg.html" width="152" height="128">
<p>画像数:
<script>
document.write(document.images.length);
</script></p>
</body>
</html>
<body>
<img border="0" src="klematis.jpg.html" width="150" height="113">
<img border="0" src="klematis2.jpg.html" width="152" height="128">
<p>画像数:
<script>
document.write(document.images.length);
</script></p>
</body>
</html>
上記の例の出力結果:
画像数: 2
試してみる »
例 2
ドキュメント内の最初の画像を返す:
<html>
<body>
<img id="サンプル1" border="0" src="klematis.jpg.html" width="150" height="113">
<img id="サンプル2" border="0" src="klematis2.jpg.html" width="152" height="128">
<p>最初の画像のID:
<script>
document.write(document.images[0].id);
</script></p>
</body>
</html>
<body>
<img id="サンプル1" border="0" src="klematis.jpg.html" width="150" height="113">
<img id="サンプル2" border="0" src="klematis2.jpg.html" width="152" height="128">
<p>最初の画像のID:
<script>
document.write(document.images[0].id);
</script></p>
</body>
</html>
上記の例の出力結果:
最初の画像のID:サンプル1
試してみる »
Document オブジェクト その他の拡張