Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM DOM Manipulation

Femke Boermans
Femke Boermans
11,240 Points

Append the newParagraph element to the content DIV element.

Hi Everyone!

Can someone explain to me what I'm doing wrong? Thanks!

app.js
const contentDiv = document.getElementById("content");
let newParagraph = document.createElement('p');
newParagraph.className = 'panel';

let div = document.getElementsByTagName('div');
div.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>

5 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Femke! If you'll look at line 1 of the code in the challenge you'll see that they already set up a variable name to hold the div with the ID of "content". Your code would select every div in the document given that you're selecting a set of elements with that tag.

Try rereading the instructions for step 3 again, knowing that you've already selected the div element with the ID content and assigned it to a variable in the first line of code.

I hope this helps, but let me know if you're still stuck! :sparkles:

Femke Boermans
Femke Boermans
11,240 Points

Hi Jennifer!

I got it now! Thank you!

contentDiv.appendChild(newParagraph);

Moderator reverted redaction

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Brent Lane! Treehouse tends to frown on copy/pasteable answers with no explanation given. I will be redacting your answer, but please feel free to repost your answer with an explanation!

That's fine. I will not comment any further after this post. I'll also be terminating my account once the month is up....since TreeHouse is such a tight moderation group with an inferior help or support systeM

Kevin Korte
Kevin Korte
28,149 Points

Brent, I have to back up Jennifer on this one - I understand you don't like the guidelines, but there is no need to try to make her feel bad for following the guidelines laid out for us. Also, I will challenge that help and support are defined by complete answers with no context and guidance. It's really not helping anyone learn something new. Sorry to see you go, we hope that you stay, but whatever you decide, best of luck to you!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Brent Lane As it so happened, I took a screenshot of that before I redacted it. After looking at the screenshot, I see that it was indeed not a copy/pasteable answer for this challenge. As such, I'm reverting my redaction. I apologize for not looking at it closer and in regards t the challenge at hand. :sparkles:

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Kevin Korte no he's right about the redaction. It was a knee-jerk reaction on my part and I should've read it more carefully. My apologies.

Randell Purington
Randell Purington
9,992 Points

Thank you because that description wasn't helping me. When I saw your comment I seen where I messed up. You actually helped me. Thank you!

Lee Holcomb
Lee Holcomb
3,535 Points

Question, why is it contentDiv.appendChild(newParagraph); and not contentDiv.appendChild("newParagraph");

Not adding the "'s threw me off.

Lee Holcomb because newParagraph is a variable.

Anne Donald
Anne Donald
9,847 Points

Hi Jennifer...

Thank you from me too, I was struggling with this for a good hour!

the kind of stuff that can drive you crazy when you are a beginer