Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Appending and Removing Nodes

Sarah Breidenbach
Sarah Breidenbach
4,490 Points

How do I place the new element p as the last child element stored in the div constant (quiz question on Appending Nodes)

const div = document.querySelector('div#feedback');
const p = document.createElement('p');
____.appendChild( ____ );

2 Answers

div.appendChild(p);

Without quotes is Variable.

appendChild is a function which acts on a parent and appends a new child. so Parent.appendChild(NewChild). In this case, what is the Parent (ie where do you want to put what you are appending?) and what is the name of the NewChild (what do you want to append?)

Sarah Breidenbach
Sarah Breidenbach
4,490 Points

I understood the basic concept but I used quotes where I shouldn't have

div.appendChild('p');

I think I was thrown because the variable was named p the same as the element.

I was also confused about having it be the last child element, but I guess it's the last one automatically.