0
[Solved]Fix the error!
https://code.sololearn.com/W4P11jq7g128/?ref=app I have figured out that SL JS gets loaded before the HTML part and added an onload function to overcome that but couldn't resolve the new errors when I put my all js inside the function . What did I do wrong ? 🤔
9 Respuestas
+ 2
I believe the compiler automatically adds it if you don't declare it as a way to be lenient on syntax. If you're developing for all browsers you probably don't want to rely on that
+ 1
This is the only part you need in the onload funtion window.onload=function(){
ele = document.getElementById("res");
}
+ 1
You need to declare it globally. Your current error is due to everything inside onload being function scoped to function().
+ 1
JME I see. That fixs everything .
0
It all works for me
0
JME Try now
0
Try to use addEventListener instead of onclick function, I too faced this problem.
I have corrected one, remaining do yourself
https://code.sololearn.com/WA2DRu9qgLOJ/?ref=app
0
JME
why I don't need to declare the ele?
0
JME Why it even works without having it declared globally ?