Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.

var contentDiv = document.getElementById('content');
var newParagraph = document.querySelector('p.myParagraph');
<!DOCTYPE html>
        <title>DOM Manipulation</title>
    <link rel="stylesheet" href="style.css" />
        <div id="content">
          <p class="myParagraph">Lorem Ipsum went to school.</p>
        <script src="app.js"></script>

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!


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.