I have a complex application and for some reason the following jQuery selector:
$('input[type=file]')
returned two jQuery elements instead of one.
So call:
$('input[type=file]').trigger('click')
The called up two file dialog box open one after another.
To solve this problem, I just applied the click trigger on the first element
$($('input[type=file]').get(0)).trigger('click');
Also, I used unbind and stopped the event propagation, here is the full code:
$('#uploadFile').click(function(evt) { evt.stopPropagation(); evt.preventDefault(); evt = evt || window.event; if(evt.target.id == 'uploadFile'){ $($('input[type=file]').get(0)).trigger('click'); } }); $(':file').unbind(); $(':file').on('change', function(evt) {
source share