How to return the number of images in a document with JavaScript?

To return the number of images in a document, use the images property in JavaScript.


You can try to run the following code to get the count of images −

Live Demo

<!DOCTYPE html>
      <img src="">
      <img src="">
      <img src="">
      <img src="">
         var val = document.images.length;
         document.write("<br>Number of images in the document: "+val);

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 23-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started