Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makeitaboldmove/b8a1e22cd32a57ab5cc3574b10322f46 to your computer and use it in GitHub Desktop.
Save makeitaboldmove/b8a1e22cd32a57ab5cc3574b10322f46 to your computer and use it in GitHub Desktop.
If input (upload) file isn't changed keep previous file attached with jQuery
let $clones = {};
$(document).ready(function(){
$(document).on('click', 'input[type="file"]', function($e){
if($(this).val() != ''){
$clones[$e.target.id] = $(this).clone();
}
});
$(document).on('change', 'input[type="file"]', function($e){
if($(this).val() == ""){
$clones[$e.target.id].insertBefore($(this));
$(this).remove();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment