I have the following jQuery code:
$("#file-upload").change(function () {
if (this.files && this.files[0]) {
$('#cancel-image-upload').html('<button type="button" class="btn btn-warning" id="cancel-upload-button" style="margin-right:15px;">cancel</button>');
}
else
$("#image-preview").attr("src", "http://placehold.it/200x150");
});
$('#cancel-upload-button').click(function () {
$("#file-upload").replaceWith('<input type="file" id="file-upload" name="file" accept="image/*">');
});
What this code does is to display cancel button after file has been chosen, and the button should be able to delete it when clicked. I tried the code above but it didn't work for some reason. Why and how can I fix it? thanks!