Count number of images available on the webpage

Hello friends, In this tutorial, we will see the HTML, CSS, and JAVASCRIPT code to Count the number of images available on the webpage.

Table Of Contents:
  • HTML CODE
  • JAVASCRIPT CODE
  • OUTPUT
  • OTHER POSTS

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384- 
  JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" 
     crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384- 
    9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384- 
    B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
  <title>Images Count</title>
</head>
<body>
 <div class="container">
      <div class="row">
        <div class="col-4 pt-5">
          <img src="https://tse4.mm.bing.net/th?id=OIP.54lzvSYm9sYvTGzA_ZdPFQHaE8&pid=Api&P=0&h=180"
          alt="this is an image"/>
        </div>
        <div class="col-4 pt-5">
          <img src="https://tse1.mm.bing.net/th?id=OIP.GmLqFon0NnPC-HhEh-fVLgHaE7&pid=Api&P=0&h=180"
          alt="this is an image"/>
        </div>
        <div class="col-4 pt-5">
          <img src="https://tse3.mm.bing.net/th?id=OIP.-D5xt6nfX4BGup0qkTmyiAHaFI&pid=Api&P=0&h=180"
          alt="this is an image"/>
        </div>  
      </div>
    </div>
    <div class="text-center">
      <button class="bg-primary text-light mt-5"onclick="countImages()">Click Here To Count The Number Of Images</button>
      <h3 class="text-danger">Total Images: <span id="count" class="text-danger"></span></h3>
    </div>
</body>
</html>

 

 

<script>
   function countImages(){
     var images = document.getElementsByTagName('IMG');
     var count = images.length;
     document.getElementById('count').innerHTML=count;    
   }
</script>

 

OUTPUT:

ALSO HAVE A LOOK AT THESE:

Validate email ID using JavaScript

Phone number validation using JavaScript

 

                                                        😊❤️THANK YOU❤️😊

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top