Created
April 28, 2014 04:33
-
-
Save fazlurr/d9303ddcb9d725697072 to your computer and use it in GitHub Desktop.
jQuery function for showing preview on image upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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