I am creating a JavaScript file that makes a basic layout of a webpage when you src
it into your HTML code. But there is an error. What is wrong? Let me show you some code.
var z = document.createElement("p");
z.innerHTML = "This is a paragraph.";
document.body.appendChild(z);
My error:
Uncaught TypeError: Cannot read property 'appendChild' of null
Please, don't say "do proper research". I already did! I googled and checked Stack Overflow for it. Anyone have any simple, working code snippets?
Edit: The code is in the < head>, not the < body>!