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 Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perform: Appending and Removing Elements

Nobuko Naito
Nobuko Naito
2,922 Points

Does the appendChild() method removes the child from its old parent?

Hi,

I understand that the following line of code:

 completedTasksHolder.appendChild(listItem);

appends the specified listItem to the completedTasksHolder.

My question is if this method call also removes the listItem from its old parent which is incompleteTasksHolder.

In other words, does the appendChild() method moves the specified child from its old parent to the new parent, rather than just append it to the new parent?

Our ToDo list application behaves that way, so I just wanted to clarify this is correct.

Thank you in advance!

1 Answer

Hugo Paz
Hugo Paz
15,622 Points

Hi Nobuko,

You are correct, since the element already exists, it is moved to its new position.

You can read more here

Nobuko Naito
Nobuko Naito
2,922 Points

Hi Hugo,

Thank you very much for your answer and the link to the documentation.

It is very clear now :)