I am dynamically creating tabs and on each tab I display an image. I then allow a new image to be selected by the user to replace it. When the new image is selected on the first tab it is displayed (the original image displayed is replaced). However, on the subsequent tabs the original image is not replaced (the new image name is displayed). The image selected on subsequent tabs are displayed on the first tab. There is no error in the console.
My html:
//Column 2 to contain the image
contents += '<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">';
contents += '<label class="control-label control-label-left col-lg-4 col-md-4 col-sm-4 col-xs-4" for="photo">Photograph:</label>';
contents += '<input class="form-control-file col-lg-8 col-md-8 col-sm-8 col-xs-8" type="file" id="photo" name="photo" placeholder="Photograph">';
contents += '<img id="campImage" src="' + obj.eventPicture + '" alt="Camp image" class="img-thumbnail">';
contents += '</div>';
js:
$(document).on('change', '#photo', function(){
readURL(this);
});
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#campImage').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}