Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following:

<div id="valueboxes" style="overflow-x:hidden;overflow-y:scroll;width:100%;height:200px">

However, every time I use the following:

document.getElementById("valueboxes").innerHTML = html;

I get this error:

'innerHTML': object is null or undefined

Am I doing something wrong?

The html is a table var being appended too by javascript in a for loop using +=.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
429 views
Welcome To Ask or Share your Answers For Others

1 Answer

That's because you are executing your code before DOM is fully loaded.

This should work:

window.onload = function() {
  document.getElementById('valueboxes').innerHTML = html;
};

Or you can simply put your javascript code just before </body> tag with no need to use onload there.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...