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;"/>
2
  • I see no upfile class there. Commented Jan 29, 2015 at 14:44
  • @Spokey check please i updated source code Commented Feb 2, 2015 at 9:33

3 Answers 3

0

try the below code :

$('.upfile')[0].trigger('click');
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

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

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

But should work for IE atleast

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.