user2659308
user2659308

Reputation: 29

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

Upvotes: 1

Views: 1441

Answers (3)

Rameez Ahmed Sayad
Rameez Ahmed Sayad

Reputation: 1300

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

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

But should work for IE atleast

Upvotes: 0

user2659308
user2659308

Reputation: 29

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

Upvotes: 0

Dee J
Dee J

Reputation: 84

try the below code :

$('.upfile')[0].trigger('click');

Upvotes: 0

Related Questions