I have a html document and after the document is loaded I want to execute some JS code that is in another file.
So far I tried it with adding an EventListener at the beginning of the JS file with event "DOMContentLoaded".
document.addEventListener("DOMContentLoaded", function () {
let file = document.getElementById("test");
function test1(){
someCode...;
using file variable;
}
function test2(){
someCode...;
using file variable;
}
});
But now all the other functions and the code is in this anonymous function. Is there another way to achieve that the JS Code only get executed after the content of the html document is loaded? Or is it ok/conventional that all the code is in this anonymous function?