An HTML file input can't be cleared by normal means (i.e. setting the value to null or an empty string), but because of browser security restrictions, most browsers don't allow this. In many browsers, setting a null value attribute either will have no effect or cause an error. Instead, create a new element that clones the old element and swap the two.
Read : How to clear HTML file inputs
Trick:- You have to create new input type file and replace it with old one.
js
function clearFileInput() {
var oldInput = document.getElementById("files1");
var newInput = document.createElement("input");
newInput.type = "file";
newInput.id = oldInput.id;
newInput.name = oldInput.name;
newInput.className = oldInput.className;
newInput.style.cssText = oldInput.style.cssText;
// copy any other relevant attributes
oldInput.parentNode.replaceChild(newInput, oldInput);
}
Updated after OP's comment
$(document).ready(function () {
function clearFileInput(el) {
var oldInput = document.getElementById(el);
var newInput = document.createElement("input");
newInput.type = "file";
newInput.id = oldInput.id;
newInput.name = oldInput.name;
newInput.className = oldInput.className;
newInput.style.cssText = oldInput.style.cssText;
// copy any other relevant attributes
oldInput.parentNode.replaceChild(newInput, oldInput);
}
$('.reset').click(function () {
clearFileInput($(this).prev('input[type="file"]').attr('id'));
});
});