Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
Comment

how to show multiple image preview in jquery

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

PREVIOUS NEXT
Code Example
Javascript :: string.fromcharcode 
Javascript :: convert string to integer in javascript 
Javascript :: how to know the current route in react class component 
Javascript :: javascript add update query parameter to url 
Javascript :: jquery remove elemtns 
Javascript :: merge arrays in javascript 
Javascript :: javascript add text to textarea overwrite 
Javascript :: what difference between react func and class components 
Javascript :: javascript await return value 
Javascript :: automatically click button javascript on setinterval 
Javascript :: download pdf javascript 
Javascript :: jquery find input and select 
Javascript :: slick js function 
Javascript :: how to add element in json object 
Javascript :: convert string time to date time object 
Javascript :: generate empty array js 
Javascript :: js sort int array 
Javascript :: running a function in a function javascript 
Javascript :: how to copy all the elements of an array except the last one in javascript 
Javascript :: get image from s3 bucket javascript 
Javascript :: appendchild on specific position 
Javascript :: jquery for element which doesnt exist on page load 
Javascript :: array from string js 
Javascript :: how to print an array javascript 
Javascript :: jquery fixed element on scroll footer 
Javascript :: timestamp to date 
Javascript :: express get 
Javascript :: Get rid of white space around Angular Material modal dialog 
Javascript :: else statement 
Javascript :: connect node server with knex database 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =