I've run accross a strange behaviour of the click event I can (more or less) figure out but I can't find documentation about.
Is it possibile to click a button using method click() from within a promise then or using a setTimeout function?
Here's an example to show what I mean:
document.getElementById("mioBottone").addEventListener("click", function () {
callAPI().then(function (data) {
document.getElementById("inputFile").click();
});
});
function callAPI () {
return new Promise (function (resolve, reject) {
$.get( "https://swapi.co/api/people/1/", function( data ) {
resolve(data);
});
});
}
From my tests it looks like click can be only executed in click event listener context and not delayed using promises or setTimeout, but I haven't found any documentation about it.
And here's a simple fiddle: https://jsfiddle.net/gpeek6s8/23/