mohsen kholaseshoar
mohsen kholaseshoar

Reputation: 347

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

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


<input type="file" name="userfile" >

Upvotes: 7

Views: 28229

Answers (3)

Peyman Mohamadpour
Peyman Mohamadpour

Reputation: 17944

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">

Upvotes: 5

Rudi
Rudi

Reputation: 2995

Select all elements by type 'file' like so:

$('[type="file"]')

Ref.: Attribute Equals Selector [name=”value”]

Upvotes: 1

ehsan ahmadi
ehsan ahmadi

Reputation: 498

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

$('input[type="file"]')

Upvotes: 30

Related Questions