JavaScript JavaScript and the DOM Making Changes to the DOM DOM Manipulation

Gareth Partridge
Gareth Partridge
11,192 Points

Finally, append the newParagraph element to contentDiv.

Iv tried various way, Suggestions are Welcome.

app.js
var contentDiv = document.getElementById('content');
var newParagraph = document.createElement("p");
newParagraph.className = "panel";
contentDiv.appendchild(newParagraph);
index.html
<!DOCTYPE html>
<html>
    <head>
        <title>DOM Manipulation</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
        <div id="content">

        </div>
        <script src="app.js"></script>
    </body>
</html>

2 Answers

Sean T. Unwin
MOD
Sean T. Unwin
Treehouse Moderator 28,623 Points

The third line, where you attempt to add a class to the new Element, is incorrect.

To attach a CSS class to an element via code we use the classList property which has a method called, add().

It should look like:

newParagaph.classList.add('panel');
KRIS NIKOLAISEN
KRIS NIKOLAISEN
53,537 Points

In testing your code I received a different error:

Bummer: There was an error with your code: TypeError: 'undefined' is not a function (evaluating 'contentDiv.appendchild(newParagraph)')

This is because the C in appendChild should be uppercase.