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) Traversing the DOM Using previousElementSibling and insertBefore

Joseph Michelini
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Michelini
Python Development Techdegree Graduate 18,692 Points

How is .removeChild() useful for traversing the DOM if you still need to create a variable that holds a reference?

Does that make sense? In the last example, and in the code challenge, we had to create a reference to the child element before ever passing it into .removeChild(). If we have to select the child element before passing it into .removeChild(), can't we just remove the child node without also selecting the parent and then passing removeChild()?

I'm sure I'm missing something...thank you in advance!

1 Answer

Steven Parker
Steven Parker
229,744 Points

You can remove an element without a reference to the parent using "remove", but it is a newer method and does not have as much browser support as "removeChild" does. Besides, it is easy to get an element's parent using the "parentNode" attribute.