Help me Out with .innerHTML | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
21st Apr 2020, 10:14 AM
Sandeep Peddi
Sandeep Peddi - avatar
3 Answers
0
Your js code is a mess ,I cudn't even care to read it !however put your js code in this function: window.onload=function(){ Js code goes here } It will stop the JavaScript running before html is loaded ,if JavaScript runs before html it will return null as there is no element with id container ,
21st Apr 2020, 11:18 AM
Abhay
Abhay - avatar
0
The problem is that the javascript part is being called before the html part has been loaded. So the id container does not exist yet when document.getElememtById("container") is called. So what you can just do is, put all the code inside a window.onload function. The format would be window.onload = function() { // the full code here }
21st Apr 2020, 11:21 AM
XXX
XXX - avatar
0
Thanks a lot
21st Apr 2020, 11:31 AM
Sandeep Peddi
Sandeep Peddi - avatar