Search code examples
javascripthtmlcssnodes

What are parent and child nodes in practical use in html?


I'm really lost on this concept. I've read up on the DOM and the definitions of nodes but I still don't really get it in a practical sense. For instance,

<div>
  <p></p>
</div>

Would <div> be the parent and <p> be the child?


Solution

  • Yes, <div> is the parent and <p> is the child

    To understand it a bit more let's add another <p>

    <div>
        <p id='first-paragraph'></p>
        <p id='second-paragraph'></p>
    </div>
    

    Now <p id='first-paragraph'> and <p id='second-paragraph'> are both children of <div>

    And one more fact is that they are siblings, since they are on the same level sharing the same parent (<div>)