jqueryangularjssafariclickjquery-trigger

jquery trigger('click') is not working in safari with angular js


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;"/>

Solution

  • 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;">