<div id="myHeading"></div>
<p>We've seen the easy way and it's caviots of modifying the DOM of the page with innerHTML in Week8, Lesson 3 and how to avoid those perils.</p>
<p>This excercise is to give you a bit more practice creating and inserting DOM elements as objects.</p>
<!-- Div to hold content -->
<div id="myParagraph"></div>
<p>See the javascript comments for further instruction</p>
<p>If you did it right, when you comment out lines 7 and 8 and run the page, nothing will change in the html result frame.</p>
JavaScript
// Create the document elements
var heading = document.createElement("h1");
var paragraph = document.createElement("p");
// Comment lines 8 and 9 out
// InnerHTML is used to add the content to the html page
//heading.innerHTML = "More Practice Creating Dom Elements!";
//paragraph.innerHTML = "The assignment is to convert the innerHTML input to DOM elements as objects.";
// You should create your nodes here;
var hText = document.createTextNode("More Practice Creating Dom Elements!");
var pText = document.createTextNode("The assignment is to convert the innerHTML input to DOM elements as objects.");
// You should add your node to the elements here:
heading.appendChild(hText);
paragraph.appendChild(pText);
// Add them to the html document.
document.getElementById("myHeading").appendChild(heading);
document.getElementById("myParagraph").appendChild(paragraph);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.