3

Here is my html code

<input type="button" id="btn" value="UPLOAD" />
<input id="fileupload" type="file" style="display:none;" />

here is jquery code

 $('#btn').click(function () {
            $('#fileupload').click();
        });

It works as expected in Chrome and in windows safari doesn't do any thing.And i checked no error in console. Here is a jsfiddle

iJade
  • 23,144
  • 56
  • 154
  • 243

2 Answers2

12

try hiding input file using the below code instead of display:none;

 opacity:0;width:0px;height:0px;
  • dats nice...i guess opacity alone will do ...no need of setting width and height to 0 – iJade Aug 30 '13 at 11:28
  • try clicking around the immediate empty space near the button, you will end up clicking the file element by mistake(which is not visible), i.e. why better set width and height to 0px as a precaution :) –  Aug 30 '13 at 11:32
  • never thought dat..thnks anywaz :) – iJade Aug 30 '13 at 11:47
1

You can also do:

input[type="file"] {
    visibility: hidden;
    position: absolute;
}
Tadas Šukys
  • 4,140
  • 4
  • 27
  • 32
thirdtiu
  • 91
  • 1
  • 5