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 Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Appending and Removing Elements

Matthew Clark
Matthew Clark
7,255 Points

I am so lost on this entire lesson...

See my attached code...

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

//Remove "Please Enable JavaScript" paragraph

  body.removeChild("#please_enable");


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

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

2 Answers

Ben Spears
Ben Spears
19,148 Points

In your code you have: body.removeChild("#please_enable");

instead of passing in "#please_enable" you should use the var that was set up to get this from the DOM.

var pleaseEnableParagraph = document.querySelector("#please_enable");

so it would look like this : body.removeChild(pleaseEnableParagraph);

using the ID selector will not work with the removeChild() method.

Jasper Leenarts
Jasper Leenarts
13,830 Points

I had no clue what to do after watching the video (and other video's in this course or the javascript fundamental courses). But with common sense, and looking stuff up in MDN I still managed to get this far.

The Javascrift basics course is much better to follow. So it would be great if this course Interactive web pages with javascript would be reviewed and altered to make it more comprehensive.

(ps perhaps when I do the course a second time, after I finish the javascript basics, everything falls in place)

I feel the same, Jasper. ;(