how to reset <input type = "file"> how to reset <input type = "file"> javascript javascript

how to reset <input type = "file">


The jQuery solution that @dhaval-marthak posted in the comments obviously works, but if you look at the actual jQuery call it's pretty easy to see what jQuery is doing, just setting the value attribute to an empty string. So in "pure" JavaScript it would be:

document.getElementById("uploadCaptureInputFile").value = "";


You need to wrap <input type = “file”> in to <form> tags and then you can reset input by resetting your form:

onClick="this.form.reset()"


This is the BEST solution:

input.value = ''if(!/safari/i.test(navigator.userAgent)){  input.type = ''  input.type = 'file'}

Of all the answers here this is the fastest solution. No input clone, no form reset!

I checked it in all browsers (it even has IE8 support).