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 trialJonathan Guerrero
Front End Web Development Techdegree Graduate 18,245 Pointshow do I assign a <p> into a variable?
I tried everything I could think of and still nothing works. Please help. Thank You
var contentDiv = document.getElementById('content');
var newParagraph = document.getElementsByTagName('p')[0];
<!DOCTYPE html>
<html>
<head>
<title>DOM Manipulation</title>
</head>
<link rel="stylesheet" href="style.css" />
<body>
<div id="content">
<p></p>
</div>
<script src="app.js"></script>
</body>
</html>
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, Jonathan Guerrero! The key to understanding this task is the first word ... "Create". The challenge means to create a paragraph without altering the HTML. You will need to erase the <p></p>
that you've added to the HTML.
Also, contrary to the previous answer, the element does not have to be in all caps. You can check out the createElement for more information about how to create an element using only JS and not altering the original HTML file.
This would have also been fine assuming that you remove the <p></p>
from the HTML.
var contentDiv = document.getElementById('content');
var newParagraph = document.createElement('p');
Hope this helps!
Peter Vann
36,427 PointsHi Jonathan!
This passes (task 1):
var contentDiv = document.getElementById('content');
var newParagraph = document.createElement('P'); // The element name must be in all caps
I hope that helps.
Stay safe and happy coding!
Jonathan Guerrero
Front End Web Development Techdegree Graduate 18,245 PointsThank You!
Jonathan Guerrero
Front End Web Development Techdegree Graduate 18,245 PointsJonathan Guerrero
Front End Web Development Techdegree Graduate 18,245 PointsThank You!