Monday, November 19, 2012

File Input resetting function

I have spent sometime to get the file input element reset correctly while I was developing a HTML5 application. I have found several ways of doing it while I was researching, but most of them were not worked as I expect. The below mentioned piece of jquery code worked fine in several desktop as well as mobile browsers. So I thought of sharing it.

works with Chrome, FireFox, Opera ,Safari and IE10 & above
$("#yourfileinput").val("");

works with < IE10
$("#yourfileinput").replaceWith($("#yourfileinput").clone(true));

No comments:

Post a Comment