I'm trying to build a multiple file upload with delete feature - something like this image:
I followed this JS Fiddle example. I am trying to remove the button with id attribute uploadBtn and use native browser file input (for the upload).
So far I have this code:
HTML
<input type="file" id="uploadFile" name="FileUpload" multiple="multiple"/>
<div id="upload_prev"></div>
JavaScript
$(document).on('click','.close',function(){
$(this).parents('span').remove();
})
$('#uploadFile').on('change', function() {
var filename = this.value;
var lastIndex = filename.lastIndexOf("\\");
if (lastIndex >= 0) {
filename = filename.substring(lastIndex + 1);
}
var files = $('#uploadBtn')[0].files;
for (var i = 0; i < files.length; i++) {
$("#upload_prev").append('<span>'+'<div class="filenameupload">'+files[i].name+'</div>'+'<p class="close" >X</p></span>');
}
}
CSS
.filenameupload {
width:98%;
}
#upload_prev {
border:thin solid #000;
width: 65%;
padding:0.5em 1em 1.5em 1em;
}
#upload_prev span {
display: flex;
padding: 0 5px;
font-size:12px;
}
But this can't list the file name with remove feature. what can I correct here?