I am trying to use the appendChild method to add a heading and some paragraph text into the in the very basic HTML file below.
<div id = "main">
<h1>Simple HTML Page</h1>
<p>This is a very simple HTML page.</p>
<p>It's about as basic as they come. It has: </p>
<li>An H1 Tag</li>
<li>An unordered list</li>
var newHeading = document.createElement("h1");
var newParagraph = document.createElement("p");
newHeading.innerHTML = "New Heading!";
newParagraph.innerHTML = "Some text for a paragraph.";
Assuming this code is inside the
<div> is loaded on the page.
<script> tag to the bottom of the page and you should no longer have the error. Alternatively, introduce an event such as
<body onload="doSomething();"> and then make a