fazlurr
4/28/2014 - 4:33 AM

jQuery function for showing preview on image upload

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