How to reset file input with JavaScript


The solution is to wrap the control in a new <form> element, use reset() method to reset the form with our file control and then remove the form using unwrap().

Compared to other solutions available that suggest using clone() this method preserves the original <input type="file"> element. It allows to retain event handlers assigned to this element.


Edit on jsFiddle

$('#btn-example-file-reset').on('click', function(e){
   var $el = $('#example-file');

Related posts

Leave a Reply

Your email address will not be published.