0

I see people using the .files extension like this:

var selectedElement = document.getElementById(id).files[0];

I only know it is part of the DOM. I've tried to search the internet to find a reference about what this does, but I can't find any. Can you guys explain or present more information about this?

DrLime2k10
  • 276
  • 1
  • 2
  • 14
dramasea
  • 3,370
  • 16
  • 49
  • 77

1 Answers1

3

It's part of the File API, which is available in all modern browsers except IE9 and earlier. files is a FileList of the file(s) selected by the user in the input[type=file] element you're referencing via the id in your id variable.

Each entry in the FileList is a File, which gives you the name of the file (without path information) and which can be used for accessing the files.

Here is a list of questions and answers about the File API here on SO.

Here are three of my answers on Stack Overflow demonstrating various ways to use the File API:

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875