Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'innerHTML': object is null or undefined

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 +=.

like image 563
Amanada Smith Avatar asked Oct 28 '25 06:10

Amanada Smith


1 Answers

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.

like image 119
Blaster Avatar answered Oct 29 '25 21:10

Blaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!