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

Nebojsa Stevanovic
Nebojsa Stevanovic
Full Stack JavaScript Techdegree Student 4,702 Points

can somebody help me with this... it doesnt work.. where did i do mistake

var contentDiv = document.getElementById('content'); var newParagraph;

newParagraph = document.createElement('p'); newParagraph.className = 'panel'; newParagraph.appendChild(contentDiv);

app.js
var contentDiv = document.getElementById('content');
var newParagraph;

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

1 Answer

Steven Parker
Steven Parker
176,598 Points

You're really close, you just need to apply the method to the existing element, and pass the new one as the argument (instead of vice-versa):

contentDiv.appendChild(newParagraph);