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

Greg Schudel
Greg Schudel
4,090 Points

Set the class of "panel"

I have absolutely no idea what the right answer for this question is and it's killing me cause I'm its stupid simple!!! (Frustrated with myself, not the problem).

I've reviewed as far as three videos back and still am completely lost.

I've tried adding everything from

newParagraph.className('.panel');

to

let newParagraph = p.className('.panel');

I have no idea what it is asking. Any one just give me the right answer? The videos have a see of methods in them and I'm returning to this lesson after taking a week on holiday.

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

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

I've even tried this

const contentDiv = document.getElementById('content');
let newParagraph = document.createElement("p").className = ".panel";

Getting no where, what am I doing wrong?

1 Answer

jacksonpranica
jacksonpranica
17,610 Points

Hey Greg,

You are so close man!!! Unfortunately className is not a function. This means that when you call class name on newParagraph, it does not have a ().

I.e

newParagraph.className('panel');

Is not appropriate. Its illegal. No way Jose.

Rather className is a property (not sure if property is the right word... attribute??? hmmm). So when setting a className, you need to treat it like setting a variable.

newParagraph.className = "panel";

That did work for me, so hopefully I am not just saying the wrong things.

Cheers!

Greg Schudel
Greg Schudel
4,090 Points

i JUST figured this out moments before your post!!

const contentDiv = document.getElementById("content");
let newParagraph = document.createElement('p');
newParagraph.className = "panel";

thanks for the input, it's helpful!