Adding table in Javascript returns null [closed]


var body = document.body;

You were using document.getElementById('body')[0]… That will not work because getElementById does not return an array, it returns a single element. Event if you didn’t have the [0], it would only work if you actually add an id of “body” to the body element…

(see fiddle:

You also used both tblbody and tblBody… You need to pick one because javascript is case sensitive.

This also throws errors:

var ndiv =  round(temp);

because you cannot “appendChild” a string onto a DOM node. Try this instead:

var ndiv =  round(temp);
cell.innerHTML = ndiv;

That will get you most of the way there. At that point the tables are getting created and you just have bugs in the “calculate” function.

Leave a Comment