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) Responding to User Interaction Event Bubbling and Delegation

John Keenan
John Keenan
13,183 Points

What is the difference between an ancestor and parent? How do ancestors, parents, and child elements relate?

Guil talks about the concept of an ancestor in the video. I am having trouble understanding the difference between an ancestor and a parent element.

2 Answers

rydavim
rydavim
18,771 Points

You can think about it as being similar to the terminology used for people.

<body> <!-- ancestor (grandparent), but not parent -->
  <div> <!-- parent & ancestor -->
    <p>Hello, world!</p> <!-- child -->
    <p>Goodbye!</p> <!-- sibling -->
  </div>
</body>

So, your parent is one generation back, and your ancestors (grandparent, great-grandparent) are further back. It's the same with elements in this case.

Hopefully that helps, but let me know if you still have questions. Happy coding!

horacinis
horacinis
4,824 Points

That is a GREAT explanation!

John Keenan
John Keenan
13,183 Points

rydavim,

Much appreciated. I get it now!