0
Can anyone explain me,why I am getting error in my JavaScript ?
4 Answers
+ 2
The javascript is loaded before HTML, which means you cannot just write
let bg = document.getElementById("bg").
If you use a console.log(bg) inside your function, you will see that bg = null.
Search on the internet how to use window.onload=function(){
//your code that should load after html
}
0
đ Alex TuÈinean đ what do u mean by "code that should load after html" ?
0
You can not acces any html element with js before it loads. The javascript loads first, so if you try to select a html element, like a paragraph, it will fail, because it won t find any html p
0
đ Alex TuÈinean đ oo yes,I had done such a dumb mistakeđ„Č,Thank you so muchđ