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

Mark Wisdom Reeves
Mark Wisdom Reeves
Full Stack JavaScript Techdegree Student 9,882 Points

Finally, append the newParagraph element to contentDiv.

var newParagraph;

newParagraph = document.createElement("p"); newParagraph = newParagraph.setAttribute("class", "panel");

var contentDiv = document.getElementById('content'); var contentDiv = document.createElement("div")[0]; var newContentDiv = contentDiv.appendChild(newParagraph);

console.log(newContentDiv);

<!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>

app.js
var newParagraph;

newParagraph = document.createElement("p");
newParagraph = newParagraph.setAttribute("class", "panel");

var contentDiv = document.getElementById('content');
var contentDiv = document.createElement("div")[0];
var newContentDiv = contentDiv.appendChild(newParagraph);

console.log(newContentDiv);
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>

1 Answer

Steven Parker
Steven Parker
182,341 Points

Here's a few hints:

  • don't change the assignment of "contentDiv" originally provided
  • when you set the attribute of "newParagraph", don't also reassign it
  • don't redeclare (or reassign) "contentDiv"
  • when you append to "contentDiv", you don't need to create or assign a new variable