:fileS2C Home « Selectors « :file

Form file selector.

Shorthand version $(':file')


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 DOM querySelectorAll() method.

The same results can be achieved with valid CSS using $('[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.


Signature Description
jQuery(':file')Form file pseudo-class match





:file Examplego to top of page Top

Selects all elements of type file.

In the example below we apply an orange background to 'file' elements within the form.

  $('.ourform').submit(function () { return false; }); // disable submit 
  $('#btn3').on('click', function() {
    $('form input:file').css('backgroundColor', 'orange');

Pie Survey     




Which pie do you prefer?:

Select a pie shape: 


Press the button below to action the above code:

go to home page Homepage go to top of page Top