Skip to content

Instantly share code, notes, and snippets.

@fazlurr
Created April 28, 2014 04:33
Show Gist options
  • Save fazlurr/d9303ddcb9d725697072 to your computer and use it in GitHub Desktop.
Save fazlurr/d9303ddcb9d725697072 to your computer and use it in GitHub Desktop.
jQuery function for showing preview on image upload
function preview(input) {
var theID = $(input).attr('data-id');
console.log(theID);
var imgPreview = $('.preview[data-id='+theID+']');
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
imgPreview.attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$('.input-image').change(function() {
preview(this);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment