Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select all input of type 'file' by jQuery?

Tags:

jquery

Select just by type, every element, <input type="file" name="userfile" >


<input type="file" name="userfile" >
like image 669
mohsen kholaseshoar Avatar asked May 28 '16 12:05

mohsen kholaseshoar


2 Answers

With this code you can select an input with type "file":

$('input[type="file"]')
like image 104
ehsan ahmadi Avatar answered Oct 29 '22 23:10

ehsan ahmadi


You may use the :file pseudo-class selector:

  • as a stand-alone :file

      $(":file")
    

or

  • on an input type: input:file

      $("input:file")
    

Example:

$("input:file").css('background', 'lightgreen');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<input type="file">
like image 34
Pmpr.ir Avatar answered Oct 29 '22 21:10

Pmpr.ir