I wrote this simple javascript code:
$("input[type='file']").attr("value", "");
It works in Firefox and Chrome but not in IE (I tried in IE9)
What's the good approach to empty the input type file value ?
Thank you
I wrote this simple javascript code:
$("input[type='file']").attr("value", "");
It works in Firefox and Chrome but not in IE (I tried in IE9)
What's the good approach to empty the input type file value ?
Thank you
There are some restriction on input type = file
You can read here
This seems to be working in IE8, IE9
$("input[type='file']").replaceWith($("input[type='file']").clone(true));
To test in IE8 I changed the compatibility mode in developer tool to IE8
Edit:
As for many IE hacks I think this is better
if($.browser.msie){
$("input[type='file']").replaceWith($("input[type='file']").clone(true));
} else {
$("input[type='file']").val('');
}
As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. In addition, .attr() should not be used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the .prop() method.
Use .prop()