Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 2
What's the difference between writing JavaScript, in js panel and html panel on Sololearn?
Because the following code gives an error on line 5, when js part is shifted to the js panel here. But it works as expected in html. https://code.sololearn.com/WHYla3IsQviX/?ref=app
5 Answers
+ 13
the difference is on the JS tab you have to make sure the DOM tree was built before referencing any DOM elements via JS.
Usually done by listening to the window.onload event
+ 10
youre welcome.
Just do this
window.onload = function(){
// Your code here
}
+ 3
Thanks「HAPPY TO HELP」 , for this. So how do I fix my problem, I'm just a beginner though.
+ 2
appears to be working fine ~ no errors being displayed
+ 1
Many user would like know that all content in JS tab will be inserted into <head> like an inline script to "execution" time then your will be executed before DOM its loaded