:file (since jQuery 1.0) selects <input type="file"> elements — the upload control. Official docs: it is equivalent to [type="file"]. Prefer $("input:file") over bare $(":file").
Syntax
Start with these common calls. Keep them short and readable.
jQuery
$("input:file") // recommended
$("form input:file") // scoped to a form
$("input[type=file]") // same matches · faster (native CSS)
$(":file") // avoid — implies *:file
// Official idea: count file inputs in a form
$("input:file").length
Call
What it does
:file
Matches input of type file
Tag / form scope
Avoids a universal * scan
Equivalent
[type="file"]
Return value
jQuery collection of matching file inputs
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Prefer $("input:file") or $("#form input:file") over bare $(":file").
Step 2
For modern speed, use $("input[type=file]") — same matches, native CSS.
Step 3
Count with .length (official demo pattern).
Return Value
Return Value
Description
See examples
Check the examples below for what this API returns in common cases.
jQuery Examples
Example 1 — Official $("input:file") Count
Report how many file inputs are in the form — the official demo pattern.
jQuery
var n = $("input:file").length;
$("#out").text("For this type jQuery found " + n + ".");
$("form").on("submit", function (event) {
event.preventDefault();
});
Global.$("input:file") includes the other form too.
Habit. Always scope on multi-form pages.
Frequently Asked Questions
:file selects every input element of type file — the control used to upload files. Prefer $("input:file"). Available since jQuery 1.0.
Yes. Official jQuery docs state that :file is equivalent to [type="file"]. For native querySelectorAll performance, prefer input[type="file"] over the :file pseudo-class.
Prefer $("input:file"). Bare $(":file") implies $("*:file") and scans every element type. Official docs recommend prefixing with a tag or other selector.
No. It is a jQuery extension since 1.0. Native querySelectorAll cannot run :file directly. Use [type="file"] for standard CSS attribute matching.
Select the control, then bind change: $("input:file").on("change", function () { var name = this.files[0] && this.files[0].name; }). File names come from the FileList on the input.
No. It only matches input elements whose type is file. Text, password, checkbox, and button inputs need their own type selectors or [type=…].