JavaScript JavaScript and the DOM Responding to User Interaction Event Bubbling and Delegation

John Keenan
PRO
John Keenan
Pro Student 5,834 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
MOD
rydavim
Treehouse Moderator 16,630 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!

John Keenan
PRO
John Keenan
Pro Student 5,834 Points

rydavim,

Much appreciated. I get it now!