(and again, code worked/works without the Page onReady() mod… (???).
Perhaps it worked this time for you also without the onLoad-command, but you should use the onLoad-command at first, like Yisrael said it. He knows very well why and what he tells you.
Normaly try always to work like this…
VERY FIRST codeline (starting point of your whole CODE)
$w.onReady(function () {
console.log("The page is ready");
})
And in most situations the SECOND codeline is often…
$w("#myDataset").onReady( () => {
console.log("The dataset is ready");
} );
So you always should start with something like…(if using DATASET for example)
$w.onReady(function () {
console.log("The page is ready");
$w("#myDataset").onReady( () => {
console.log("The dataset is ready");
});
});
END-RESULT…
$w.onReady(function () {
$w("#myDataset").onReady( () => {
//here put in all your CODE
//for example put in a button On-Click-Function here....
$w("#myButton1").onClick(()=>{
console.log("Button1 clicked.")
})
//with coding-structure like this, you do not need to connect your button with the code anymore. It does do it automatically.
});
});
Why using all this onReady-Coding?
Because sometimes there are laoding-times which need time, but your code do not stop and wait for this LOADING-TIMES, and it is very often the situation, where you will get wrong results or even NO-RESULTS (like in your own example), because you have programmed your code in that way, that it do not wait for completed LOADINGS. The CODE just runs and ignores everything else (does not wait for response/answer.)
And now, this post can be closed i think.
P.S.: This is why i told you in one of my posts, that you have to be careful working with —> Async-Await / .then(()=>{} commands. The “onLoad”-command is also one of these very important commands.