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 trialJoseph Michelini
Python Development Techdegree Graduate 18,692 PointsHow 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
231,236 PointsYou 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.
Joseph Michelini
Python Development Techdegree Graduate 18,692 PointsJoseph Michelini
Python Development Techdegree Graduate 18,692 PointsSteven you've done it again. Thank you.