<input type="file" />
<div class="output"></div>FileList: item() method / notebook
FileList: item() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const fileInput = document.querySelector("input[type=file]");
const output = document.querySelector(".output");
fileInput.addEventListener("change", () => {
const fileList = fileInput.files;
if (fileList.length > 0) {
const file = fileList.item(0);
output.textContent = `You selected: ${file.name}`;
}
});