how to show multiple image preview in jquery

function previewImages() {

  var preview = document.querySelector('#preview');
  
  if (this.files) {
    [].forEach.call(this.files, readAndPreview);
  }

  function readAndPreview(file) {

    // Make sure `file.name` matches our extensions criteria
    if (!/\.(jpe?g|png|gif)$/i.test(file.name)) {
      return alert(file.name + " is not an image");
    } // else...
    
    var reader = new FileReader();
    
    reader.addEventListener("load", function() {
      var image = new Image();
      image.height = 100;
      image.title  = file.name;
      image.src    = this.result;
      preview.appendChild(image);
    });
    
    reader.readAsDataURL(file);
    
  }

}

document.querySelector('#file-input').addEventListener("change", previewImages);

4
3

                                    <input id="file-input" type="file" multiple>
<div id="preview"></div>

4 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
multiple image preview before upload jquery demo jquery upload multiple images with preview jquery multiple preview images frm url how to multiple image preview in jquery preview multiple image before upload jquery jquery multiple preview images Add & preview multiple images jquery html & css preview & uplod multiple images html jquery Multiple image file with preview jQuery Plugin preview multiple image before upload jquery medium select multiple image and display jquery multiple image preview using jquery how to upload multiple images in jquery display multiple image preview before uploading jquery preview image from multiple input jquery upload multiple images with preview jquery jquery multiple image upload with preview plugin How to display multiple images in jquery multiple images edit display jquery how to add multiple images using jquery multiple photos preview uaing jquery preview multiple phtos with jquery multiple selected image preview in jquery multiple image preview in jquery multiple image upload and preview in jquery jquery multiple image upload with preview how to show multiple image preview in jquery multiple image preview jquery upload multiple image in html and display multiple image upload and preview upload multiple images and view as gallery in html preview multiple images before upload javascript multi image uploader with preview show multiple image preview before upload jquery javascript preview multiple image selected on loacsl product multiple image preview in jquery
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source