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 trialCosmina Iosifescu
6,432 PointsBug on test in Javascript and the DOM
I keep getting the message: "Bummer: Make sure that you assign a '<p>' element to 'newParagraph'.", even though I have created the element in index.html and assigned it correctly. My HTML:
<body>
<div id="content">
<p>Paragraph</p>
</div>
<script src="app.js"></script>
</body>
const contentDiv = document.getElementById('content');
const newParagraph = document.querySelector('p');
Am I missing something here? Or is this really a bug?
const contentDiv = document.getElementById('content');
const newParagraph = document.querySelector('p');
<!DOCTYPE html>
<html>
<head>
<title>DOM Manipulation</title>
</head>
<link rel="stylesheet" href="style.css" />
<body>
<div id="content">
<p>Paragraph</p>
</div>
<script src="app.js"></script>
</body>
</html>
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Cosmina Iosifescu! Maybe the challenge should say dynamically create a new paragraph without altering the HTML file. It's looking for you to use the createElement()
method here.
var newParagraph = document.createElement('p');
It's giving you the HTML for reference, but you should not need to modify the HTML file. The point of this exercise is to use JavaScript to create that element
Hope this helps!
Daniel Grzegorczuk
7,172 PointsDaniel Grzegorczuk
7,172 PointsHi. Try using document.getElementByTagName instead of document.querySelector. Your code is correct, but Treehouse wants you to use syntax you learned in the previous video. I remember I had the same problem with this task.