Skip to content

Instantly share code, notes, and snippets.

@amitpatelx
Last active November 20, 2015 10:27
Show Gist options
  • Save amitpatelx/d084cda55b0205026bc2 to your computer and use it in GitHub Desktop.
Save amitpatelx/d084cda55b0205026bc2 to your computer and use it in GitHub Desktop.
Clear selected file - HTML
// Once you select any file from file input, there is no way user can unselect it.
//Soluction
// Clear any input, including <input type='file' />
// http://stackoverflow.com/a/13351234/517483
window.smartReset = function (e) {
e.wrap('<form>').closest('form').get(0).reset();
e.unwrap();
}
//Call the function passing jQuery object of selected file element
$('#remove_post_sponsor_logo_link').on('click', function(){
smartReset($('#post_sponsor_logo'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment