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 JavaScript and the DOM (Retiring) Making Changes to the DOM DOM Manipulation

Joel Venable
Joel Venable
6,494 Points

Is 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.

app.js
var contentDiv = document.getElementById('content');
var newParagraph = document.querySelector('p.myParagraph');
index.html
<!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

Hey 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

A 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
Joel Venable
6,494 Points

Worked like a charm. Thanks.