Reputation: 11177
<input
type="file"
id="fileElem"
multiple
accept="image/*"
style="display:none"
onchange="handleFiles(this.files)">
<a href="#" id="fileSelect">Select some files</a>
<div id="fileList">
<p>No files selected!</p>
</div>
When I selected 5 files: How to dynamically remove some of them?
I know how clear all files How can I clear an HTML file input with JavaScript?
Upvotes: 1
Views: 1140
Reputation: 13943
$("#fileElem")[0].files
is a read-only array.
You can get around this by pushing those files into a separate Array though. You can then do whatever you want with that curated list of files. If uploading them to a server is the goal, you can use the FileReader
API.
Below is a round about way of completely avoiding needing to modify the FileList. Steps:
FileReader
API to read files locallyUpvotes: 1