im trying to insert a new div into the DOM with an id of “app”
var new_div = document.createElement("div");
var app_div = document.getElementById("app");
document.body.insertBefore(new_div, app_div);
this gives me an error in the console:
Uncaught TypeError: Cannot call method ‘insertBefore’ of null
but i don’t know why?
You need to wrap your code to window.onload handler:
Example on jsFiddle.