Preview an image before it is uploaded in Jquery Ask Question
By       29-Apr-2025    1

How to Preview image before it is uploaded or how to view image on choose.

Solutions


Adil Shahbaz

Here is the code of preview image before it is uploaded.

Please make sure you have already added jquery reference.

function readImageUrl(input) {

  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('#previewImg').attr('src', e.target.result);
    }

    reader.readAsDataURL(input.files[0]);
  }
}

$("#uploadedImg").change(function() {
  readImageUrl(this);
});


<input type='file' id="uploadedImg" />
  <img id="previewImg" src="#" alt="Your Image" />

10021
Copyright Future Minutes © 2015- 2025 All Rights Reserved.   Terms of Service  |   Privacy Policy |  Contact US|  Pages|  Whats new?
Update on: Dec 20 2023 05:10 PM