Clear/Reset input type="file" (upload field) with jQuery

http://stackoverflow.com/a/13351234/2507142

HTML

<form>
    <input id="file" type="file">
    <br>
    <input id="text" type="text" value="">
</form>

<button onclick="reset($('#file'))">Reset file</button>
<button onclick="reset($('#text'))">Reset text</button>

JavaScript

// wraps a <form> around the element, calls reset on the form, then removes the form using unwrap().

window.reset = function (e) {
    e.wrap('<form>').closest('form').get(0).reset();
    e.unwrap();
}