1

Jquery trigger('click') is not working on Safari and IE, but working on Mozilla , chrome,

I Am using AngularJS and here is my code snippet

$scope.browseFile = function () {        
    $('.upfile').trigger('click');
    console.log('click','fired browseFile');      

}  

And here is HTML code

 <a class="btn-attach pull-left" data-ng-click="browseFile()">Attach <i class="glyphicon glyphicon-paperclip"></i></a><input type="file" name="file" class="upfile" id="upfile" onchange="angular.element(this).scope().uploadFile(this.files)" style="display: none;"/>

3 Answers3

0

try the below code :

$('.upfile')[0].trigger('click');
Dee J
  • 84
  • 1
0

its a css trick, and it not possible to fire event on hidden element on safari , so i did some changes and here is that- basically on style - style="font-size:1px;opacity:0; height:1px; width:1px;visibility: hidden;" and its work for me every browser

<input type="file" name="file" class="upfile" id="upfile" onchange="angular.element(this).scope().uploadFile(this.files)" style="font-size:1px;opacity:0; height:1px; width:1px;visibility: hidden;">
0

Originally from https://stackoverflow.com/a/21073094/2149740

$(event.target).trigger('input').trigger('change').trigger('keydown');

But should work for IE atleast

Community
  • 1
  • 1
Rameez Ahmed Sayad
  • 1,300
  • 6
  • 16
  • 29