:file
S2C Home « Selectors « :file
Form file selector.
Shorthand version $(':file')
Description
The :file
selector, selects all elements of type file.
- Being a jQuery extension the
:file
pseudo selector is not part of any current CSS specification. Therefore:file
cannot take advantage of the performance boost provided by the native DOMquerySelectorAll()
method. - The same results can be achieved using the Attribute Equals Selector via
$('[type=file]')
, without the hit to performance. - If this selector is not preceded by another selector, the universal selector ("*") is implied and so the whole DOM will be searched. Use another selector as in the example below to narrow the search and improve performance.
Syntax
Signature | Description |
---|---|
jQuery(':file') | Form file pseudo-class match |
Parameters
None.
Return
N/A.
:file
ExampleTop
Selects all elements of type file.
In the example below we apply an orange background to 'file' elements within the form.
$(function(){
$('.ourform').submit(function () { return false; }); // disable submit
$('#btn1').on('click', function() {
$('form input:file').css('backgroundColor', 'orange');
});
});