JavaScript for WordPress › Forums › Vanilla JavaScript › 1.3.04 – Traversing the DOM – Differences between parentElement and parentNode › Reply To: 1.3.04 – Traversing the DOM – Differences between parentElement and parentNode
You are doing exactly the right thing!!!
There are instances when this type of skill comes in handy. For example, in the sidebar of the site students requested that the navigation toggle open and closed. To know when you click on a link what it’s parent is and how many children it has can be very helpful and necessary. I understand though if the concept seems a little abstract for the moment.
For selecting a second child you would get the array of all children and then use array[x] to get the specific child you needed. Or you could get the first child and then the next sibling of that one.
Again, this may seem like a silly or not helpful exercise, but as a front end dev there will absolutely be a time when buying complex UIs and interaction where you will need to get parents several levels up and work with children and siblings 🙂
Hope that helps and awesome work following along with the suggested exercises!!!