Below is part of the jquery code I have which displays the file input and a \"Clear File\" button.
var $imagefile = $(\'\').attr({
type: \
This works to
$("#yourINPUTfile").val("");
Clear file input with jQuery
$("#fileInputId").val(null);
Clear file input with JavaScript
document.getElementById("fileInputId").value = null;
By Setting $("ID").val(null)
, worked for me
for React users
e.target.value = ""
But if the file input element is triggered by a different element (with a htmlFor
attribute) - that will mean u don't have the event
So you could use a ref:
at beginning of func:
const inputRef = React.useRef();
on input element
<input type="file" ref={inputRef} />
and then on an onClick function (for example) u may write
inputRef.current.value = ""
this.inputRef = React.createRef()
get input id and put val is empty like below: Note : Dont put space between val empty double quotes val(" ").
$('#imageFileId').val("")