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 trialP. HOEKJAN
Courses Plus Student 1,966 PointsparentNode or parentElement
For step 6 and 7 I used parentElement instead of parentNode which had the same effect. What's de difference between those and how do I know which one to use?
1 Answer
Steven Parker
231,248 PointsAn element is a specific type of node. So when the parent is an element (as usual), both properties will return the same thing. In the unlikely case where the parent is not an element, parentNode will still return the parent but parentElement will return null.
Since in this example the traversal is specifically to an enclosing div element, the parentElement property is perhaps a better choice.
JASON PETERSEN
14,266 PointsJASON PETERSEN
14,266 PointsHad the same question. I found an answer on this on stack overflow. https://stackoverflow.com/questions/9979172/difference-between-node-object-and-element-object