Trigger event not working in IE10
I need to add an event onclick
to the image, so when I click on the image it brings up the file open dialog. But that doesn't work in IE10.
$("#button").on("click",function(){
$("#upload").trigger("click");
});
#upload{
opacity: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<img id="button" src="http://www.kafkabrigade.org.uk/wp-content/uploads/2011/07/button-pic.jpg" />
<input id="upload" type="file" >
0
source to share
2 answers
Ok, I tested this in newest FF, Opera, Chrome, IE8, IE9, IE10, IE11. His work is everywhere.
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="file" />
<img id="button" src="http://www.kafkabrigade.org.uk/wp-content/uploads/2011/07/button-pic.jpg" />
JQuery
$('#button').click(function() {
$('input[type=file]').trigger('click');
});
$('input[type=file]').change(function() {
$('input[type=text]').val($(this).val());
});
CSS
input[type=file] {
display: block;
height: 0;
width: 0;
}
0
source to share