Counting the images of the document using JavaScript:
To count the images of the document we write the script something like this:
document.write("This document contains: " + document.images.length + " images.")
Here document.write is used to display the output and document.images.length is used to counting the images.
For Example:
<html>
<head>
<title>Image Counting</title>
</head>
<body bgcolor="#ffcccc">
<img border="2" src="btn.gif" width="100" height="100">
<img border="2" src="tn00738a.gif" width="100" height="100"><br /><br />
<img border="2" src="tn00897_.gif" width="100" height="100">
<img border="2" src="icons.jpg" width="100" height="100"><br /><br />
<script type="text/javascript">
document.write("This document contains: "+ document.images.length + " images.")
</script>
</body>
</html>
First of all you load the images after that write the script in the body section.
Output: Output of the script is given as follows:

Figure: In this document four images are used.