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 trialFabrice Innocent
Full Stack JavaScript Techdegree Student 9,715 PointsNext steps with setting the class attribute
A bit confused here. I'm assuming I should be building upon each steps code, so how do I assign a new attribute to the newParagraph variable if I have to already assign it to the "p" variable?
let p = document.createElement('p');
let att = document.createAttribute('panel');
att.value = 'panel';
var contentDiv = document.getElementById('content');
var newParagraph = p;
newParagraph.setAttributeNode('panel')
<!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
Armin Kadic
16,242 Pointsvar contentDiv = document.getElementById('content');
var newParagraph = document.createElement("p"); /* Create it right away without making an individual variable for it */
newParagraph.className = "panel"; /* Add/change the class name to "panel" */
contentDiv.appendChild(newParagraph); /* Attach the new paragraph to the desired node. */
Hope this helps!
Fabrice Innocent
Full Stack JavaScript Techdegree Student 9,715 PointsFabrice Innocent
Full Stack JavaScript Techdegree Student 9,715 PointsThanks so much! Will be going back over the videos to make sure I grasp the concept a bitt better