You can find the working file at Jsfiddle
/* JavaScript */
function readURL() {
var $input = $(this);
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$input.next('.blah').attr('src', e.target.result).show();
$input.after('<input type="button" class="delbtn" value="remove">');
}
reader.readAsDataURL(this.files[0]);
}
}
$(".imgInp").change(readURL);
$("form").on('click', '.delbtn', function(e) {
var $input = $(this);
$input.next('.blah').attr('src', e.target.result).hide();
$input.prev('.imgInp').val("");
$(this).closest(".delbtn").remove();
});
<form name="" action="" method="post">
<div class="div">
<input type='file' class="imgInp blah" />
<img class="blah" src="#" alt="your image"/></div>
<br>
<br>
<div class="div">
<input type='file' class="imgInp" />
<img class="blah" src="#" alt="your image"/></div>
</form>
Display and remove image is working fine.
But if the image already selected and again select another new image then preview function is not working. Also remove button keep adding. Please check the error image below.