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

terry okey
terry okey
3,187 Points

set class attribute to panel

Oh this is so frustrating, and seems like such a long way to learn something. I've been through my extensive notes and on the web and I still can't get this stupid little thing. I've spent a lot of time researching and then just guessing but it could be anything. Can anyone help me with how to set the class attribute to panel?

app.js
var contentDiv = document.getElementById('content');
var newParagraph = document.createElement('p');
var newParagraph = document.createAttribute(class '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>

1 Answer

in order to set the class attribute, you would write

newParagraph.className = 'panel';

you don't need to declare a new variable for it - hope this helps!