How to work with document.images in JavaScript?


Use the document.images property in JavaScript to get the number of <img> tags in a document.

Example

You can try to run the following code to implement document.images property in JavaScript.

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Example</title>
   </head>
   <body>
      <h1>TutorialsPoint Tutorials</h1>
      <img src="/javascript/images/javascript-mini-logo.jpg"/><br>
      <img src="/html5/images/html5-mini-logo.jpg"/>
      <script>
         var num = document.images.length;
         document.write("<br>How many images? "+num);
      </script>
   </body>
</html>

Updated on: 20-May-2020

301 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements