0

I need to add onclick event to an image so when I click on the image it will trigger the file open dialog. But it 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" >
Legionar
  • 7,472
  • 2
  • 41
  • 70
yaibait
  • 86
  • 2
  • 10

2 Answers2

0

Ok, I tested this in the newest FF, Opera, Chrome, IE8, IE9, IE10, IE11. Its working 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;
}

Working DEMO

Legionar
  • 7,472
  • 2
  • 41
  • 70
-1

This should answer your question.

zamber
  • 938
  • 8
  • 25