Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Krasnov8953/5c4f4cdc829537ed6c42f74130835240 to your computer and use it in GitHub Desktop.
Save Krasnov8953/5c4f4cdc829537ed6c42f74130835240 to your computer and use it in GitHub Desktop.
drag and drop files to input type file
$(document).ready(function(){
$('body').on('dragenter', function(){
$('input[type="file"]').addClass('drag');
console.log('enter');
});
$('input[type="file"]').on('dragleave', function(e){
e.stopPropagation();
$('input[type="file"]').removeClass('drag');
console.log('leave');
});
$('body').on('drop',function(){
$('input[type="file"]').removeClass('drag');
$('input[type="file"]').on('change', function (event, files, label) {
var file_name = this.value.replace(/\\/g, '/').replace(/.*\//, '')
$('.filename').text(file_name);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment