Вот выполнение моего JavaScript: < /p>
ee_btn.addEventListener('click', () => {
//Ajax GET request to get data form and rendering it
RequestEEFormData(container, bounds).then(()=>{
// Loading a javascript file. it get loaded.
// I can call function from this file then.
loadScript('/static/js/locationConverterWidget.js');
});
});
< /code>
function loadScript(url) {
const script = document.createElement('script');
script.src = url;
script.async=false;
script.onload = function(){
//trying to querySelector newly added content
console.log(document.querySelector('#id_item);
}
document.head.appendChild(script);
}
< /code>
in case:
async function RequestEEFormData(container, bounds) {
$.ajax({
type: 'GET',
url: 'someURL/',
success: function (response) {
container.innerHTML=response;
someFunction(bounds)
},
error: function(response){
console.log(response);
},
cache:false,
contentType: "application/json",
processData: false
});
}
< /code>
the console.log return an empty Nodelist.
if I do call the same consol.log from a button 1sec later. It work.
Clearly there is something with the async I dont understand.
Can anyone explain my what I'm doing wrong ?
the purpose is I want the newly downloaded javascript file to querySelector newly added content but It seems to be executed prior the html is completely rendered.
thank you
Подробнее здесь: https://stackoverflow.com/questions/795 ... -execution