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 trialStephen Printup
UX Design Techdegree Student 45,252 PointsPerform: Appending and Removing Elements; Challenge 1 of 2
Take a look around at the app.js and index.html files. In this task we're going to remove the pleaseEnableParagraph from the body. Do that around line 7.
I've tried both:
var body = document.body;
var newParagraph = document.createElement("p");
var pleaseEnableParagraph = document.querySelector("#please_enable");
//Remove "Please Enable JavaScript" paragraph
var deleteTask = function () {
var listItem = this.parentNode;
var ul = listItem.parentNode;
ul.removeChild (pleaseEnableParagraph);
}
//Append new paragaph to document
and
var body = document.body;
var newParagraph = document.createElement("p");
var pleaseEnableParagraph = document.querySelector("#please_enable");
//Remove "Please Enable JavaScript" paragraph
var deleteTask = function () {
body.removeChild (pleaseEnableParagraph);
}
//Append new paragaph to document
The index markup is
<!DOCTYPE html>
<html>
<body>
<p id="please_enable">Please Enable JavaScript</p>
<script src="app.js"></script>
</body>
</html>
I've looked on MDN and found ChildNode.remove() but it says it is an experimental technology. Will someone please help me? Thank you.
4 Answers
Jeff Busch
19,287 PointsHi Stephen,
You're over-thinking it. Try this:
body.removeChild(pleaseEnableParagraph);
Jeff
Stephen Printup
UX Design Techdegree Student 45,252 PointsThanks, I thought I did try that and got an error telling me to put it in a function. Oh well, it worked!
Russell Roberts
21,482 PointsI probably was over thinking it as well because did the same thing. Thanks for the help.
Michael Brown
17,651 PointsThe answer is body.removeChild(pleaseEnableParagraph); A lot of times an error occurs is usually a typo. That's why it doesn't work for me most of the time.
Larry Singleton
18,946 PointsThis is what worked for me. This part is the most confusing for me.
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
Rich Braymiller
7,119 PointsRich Braymiller
7,119 PointsYeah well Andrew makes one over think. MY least favorite instructor on Treehouse.