Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Appending and Removing Elements

kevinthecoder
kevinthecoder
10,791 Points

Unable to Append the new Paragraph. Please help.

Man, this stuff is tough. I just can't wrap my head around this stuff. Again, the first two of three sections were no problem but this third section is wiping me out. Can anyone help? What am I doing wrong? I've looked at my code and watched the video three times and I'm still not getting it. Any help is appreciated. I can do the first challenge but not the second one. Thanks.

app.js
var body = document.body;
var newParagraph = document.createElement("p");
var pleaseEnableParagraph = document.querySelector("#please_enable");

//Remove "Please Enable JavaScript" paragraph

body.removeChild(pleaseEnableParagraph);

//Append new paragaph to document
document.appendChild(pleaseEnableParagraph);
index.html
<!DOCTYPE html>
<html>
  <body>
    <p id="please_enable">Please Enable JavaScript</p>

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

2 Answers

Erik McClintock
Erik McClintock
45,783 Points

Kevin,

You've got two fairly small errors here: The task is instructing you to append the "newParagraph" element to the BODY, but you're currently appending the "pleaseEnableParagraph" element to the DOCUMENT.

You want:

body.appendChild(newParagraph);

Not:

document.appendChild(pleaseEnableParagraph);

I know the comment in the text editor is confusing, but the true instruction is up above on that page :)

Erik

kevinthecoder
kevinthecoder
10,791 Points

Ah, OK (duh!!) . HAHAHAHA. :) I couldn't help but laugh at what I did. It's the words that threw me. Thanks, Eric!