0

I have a file input element as in code below. How would I get the button part of this file input control using jQuery?

<input type="file" name="FILE1" id="FILE1"></input>
3
  • You can't, take a look at my answer to this question Commented Jul 8, 2012 at 20:35
  • This has nice answers/hacks Commented Jul 8, 2012 at 21:02
  • @elclanrs - Thanks for the help. Its a nice approach to styling file input control with jQuery. Commented Jul 8, 2012 at 21:05

3 Answers 3

1

that's not possible because file input behavior is under control of the browser and manipulating that causes security-related issues like preventing the file-upload. however you can set the opacity of file input to 0, and create a dummy element instead and trigger the click event for file input by clicking that:

$("#trigger").click(function(e) {
   e.preventDefault();
   $("input[type='file']").trigger("click");        
}) 
Sign up to request clarification or add additional context in comments.

3 Comments

I dont think its possible to trigger click cross browser (security reasons). Also, changing opacity to 0 shouldnt affect its clicking ability.
@Jashwant i have used this method for my website and it works in all browsers, but instead of input[type='file'] an id can prevent security problems.
click is actually the only event that works across browsers. change on the other hand has some problems.
1

You can't. The button part is browser specific.

Comments

0

There are a number of questions and answers on this that cover what you can do with a file input. It's not much, but it is something.

Style input type file?

Erick

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.