Search code examples
jqueryinternet-explorershow-hide

Remove selected file from Input type = File in IE


How to clear selected file in IE

Following example works in chrome but not in IE (Any version)

http://jsfiddle.net/nfvR9/1/

HTML

<input id="file1" type="file" class="" multiple="" required="" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />

Jquery

$("#fileUpload").val('');

As expected IE does not support this.


Solution

  • I end up doing as below:

    function reset_form_element(e) {
                e.wrap('<form>').parent('form').trigger('reset');
                e.unwrap();
            }
    

    and then called the function as below:

    reset_form_element($('#file1'));