Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7853511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:43:18+00:00 2026-06-02T19:43:18+00:00

I was doing some tests on html 5 file upload with jquery and ran

  • 0

I was doing some tests on html 5 file upload with jquery and ran into something strange (at least to me). I was trying to get the list of files that had been selected in the file control :

<html><head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type">
  <script src="http://code.jquery.com/jquery-1.7.1.js" type="text/javascript"></script>
</head>
<body>
    <input type="file" multiple="multiple" id="inputFile" name="inputFile">
    <button onclick="buttonClicked()" type="button">upload</button>
<script type="text/javascript">//<![CDATA[ 
function buttonClicked() {
    console.log($("#inputFile").val()); // depending on the browser, gives either the file name, either the full path, but only for the first file
    console.log($("#inputFile").files); // gives undefined
    console.log($("#inputFile").attr("files")); // gives undefined
    console.log($("#inputFile").get()); // according to the jquery documentation, give the dom element...
    console.log($("#inputFile").get().files); // ...but strangely, files is undefined
    console.log($("#inputFile")[0].files); // on the other hand, this gives me the list of files
}
//]]>;  
</script>
</body></html>

So first I was expecting that $(“#inputFile”).val() would give me that least, too bad that’s not the case. So I tried variations on input.files, without really expecting it to work because it didn’t seem to fit a jquery object (but hey, you never know). So I tried to get the underlying dom element from jquery to access the files item. And that’s where it get strange because it’s undefined as well. On the other hand$(“#inputFile”)[0].files gives the expected result.

[Edit]
And then, as often, while typing that question, I found the solution myself. I’ll leave it here anyway, so anyone who struggle on that has a chance to solve it also. It basically goes on RRTFM, like Really RTFM :

All of the matched DOM nodes are returned by this call, contained in a
standard array

That means, even if there is only one element. So the call:

console.log($("#inputFile").get());

Was returning an array with one element, and of course arrays don’t have a files property. It should have been:

console.log($("#inputFile").get(0)); 
console.log($("#inputFile").get()[0]); // or this one, but that's a bit silly
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:43:19+00:00Added an answer on June 2, 2026 at 7:43 pm

    The problem is, besides the fact that .get() returns an array (.get(0) gives you the first element) that you use .attr() instead of .prop().

    If you want elem.files, the jQuery way to access it is $(elem).prop('files').

    When using .attr() that corresponds to a call to .getAttribute() which is usually not what you want for properties such as files or checked. jQuery sometimes automatically switches to properties, e.g. for checked, but of course it cannot cover every single property.

    So, what you finally want to use, is $('#inputFile').prop('files') or $("#inputFile").get(0).files. However, the latter will throw an error if your selector did not match anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this page I'm doing some tests in Javascript and jQuery: JS Tests
I am doing some performance tests of a HTML stripper (written in java), that
I'm doing some tests with new features of CSS3, but this combination only works
I'm doing some tests, but I see no difference when I use or not
I am doing some tests, just to learn (normally i do this in ajax
I'm basically just doing some tests to figure out a good way to write
I'm new in Silverlight and i am doing some tests. With my current test
I'm developing an application with Spring 3. I'm doing some tests with spring batch.
I'm doing some unit tests for an EntityEventListener from NHibernate, and I'm got stuck
While doing some JavaScript performance tests I came up with the following piece of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.