I am testing this idea of using a div on top of an invisible <input type="file" /> so I can make a fancy file uploading button. I have seen some code around but was somewhat complicated. I thought of trying this idea of using jQuery to trigger the click of the input tag from its div container
Html:
<div id="container"> Click Me!
<input type="file" id="file" />
</div>
Javascript:
$(document).ready( function() {
$('#container').click( function() {
$('#file')[0].click();
})
});
Although the code runs OK on Chrome and IE, it does not run on Safari and it has a funny problem with Firefox: it triggers the click twice! Any idea why this is so? jQuery is supposed to be cross-platform and I am puzzled. Here is the fiddle
http://jsfiddle.net/kostasd/C4sCs/1/
Thanks in advance for any help!
Kostas
display:block;position:absolute;top:0;left:-9999px;, then wrap it with a container that hasposition:relative;overflow:hidden;width:somepx;. DO NOT USE display:none. Then trigger your click; bam, cross-browsers support .display: hidden