javascript - Cannot read property 'appendChild' of null - JS error -
this question has answer here:
first question here!
i've been doing js recently, i'm stuck on error, nature don't understand. understand there quite few of threads that, solutions i've found don't seem work in case. here's code:
function codeinsert() { var overcodemake = document.createelement("div"); overcodemake.id = "overcode"; var body = document.getelementbyid("body"); body.appendchild(overcodemake); var undercodemake = document.createelement("input"); undercodemake.id = "undercode"; undercodemake.type = "text"; undercode.placeholder = "code"; var overcodemade = document.getelementbyid("overcode"); overcodemade.appendchild(undercode); }
all ids on positions, looks logical, yet keep getting "cannot read property 'appendchild' of null" error. reason? or not understand here?
replace
var body = document.getelementbyid("body");
with
var body = document.body;
Comments
Post a Comment