MDN self-hosted library · e01.org
FileList / notebook

FileList

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<input id="fileItem" type="file" />
js
const file = document.getElementById("fileItem").files[0];
html
<input id="myfiles" multiple type="file" />
<pre class="output">Selected files:</pre>
css
.output {
  overflow: scroll;
  margin: 1rem 0;
  height: 200px;
}
js
const output = document.querySelector(".output");
const fileInput = document.querySelector("#myfiles");

fileInput.addEventListener("change", () => {
  for (const file of fileInput.files) {
    output.innerText += `\n${file.name}`;
  }
});