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 trialJoel Venable
6,494 PointsIs this test question broken? I have assigned a '<p>' element to 'newParagraph' as requested, but I cannot continue.
I have tried a variety of methods and selectors with no change.
var contentDiv = document.getElementById('content');
var newParagraph = document.querySelector('p.myParagraph');
<!DOCTYPE html>
<html>
<head>
<title>DOM Manipulation</title>
</head>
<link rel="stylesheet" href="style.css" />
<body>
<div id="content">
<p class="myParagraph">Lorem Ipsum went to school.</p>
</div>
<script src="app.js"></script>
</body>
</html>
1 Answer
Dylan Glover
2,537 PointsHey Joel,
This question wasn't broken, just not very well worded. It confused me too, but it basically wanted you to create the <p> element using the JavaScript .createElement()
method. So you don't need a <p> tag in your index.html and you would add this to your JS.
var contentDiv = document.getElementById('content');
var newParagraph = document.createElement('p');
I believe the way you had it set up would run normally and would allow you to select a specific <p> element by class, the question just wanted you to do it differently.
Hope that helps!
Dylan
Dylan Glover
2,537 PointsDylan Glover
2,537 PointsA lot of times when the question is not very helpfully worded and I don't know what method it wants me to use, I'll watch the video immediately before the challenge again just to get context clues as to what they're looking for. But with JavaScript and coding in general there are often many different paths to reach the same destination. Thinking outside the box is never a bad thing!
Joel Venable
6,494 PointsJoel Venable
6,494 PointsWorked like a charm. Thanks.