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

Chanel Weathers
Chanel Weathers
7,003 Points

Im certain Ive assigned <p> to the variable, but it keeps giving me an error, not understanding why.

I added a <p> element to the HTML & I assigned the newParagraph variable to the <p> element in the js file using the querySelector method which I believe is correct but still getting and error.

app.js
var contentDiv = document.getElementById('content');
let newParagraph = document.querySelector('p');
index.html
<!DOCTYPE html>
<html>
    <head>
        <title>DOM Manipulation</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
        <div id="content">
        </div>
        <p class="para"></p>

        <script src="app.js"></script>
    </body>
</html>

2 Answers

Piotr Manczak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Piotr Manczak
Front End Web Development Techdegree Graduate 28,940 Points

As far as I can understand you created <p> directly in HTML but they are asking you to do that in JavaScript, like that:

var contentDiv = document.getElementById('content'); var newParagraph = document.createElement('p');

and next: newParagraph.className = 'panel'; and then:

contentDiv.appendChild(newParagraph);

if that helps don't forget to upvote me, please.

Chanel Weathers
Chanel Weathers
7,003 Points

Thanks!! looks like i was using the wrong method.

Josh Ballard
Josh Ballard
697 Points

Hi Chanel,

Can you post the error message? You created a new paragraph element, but you haven't appended it to the DOM. Is that what you are referring to?

-Josh