JavaScript DOM | Part 2 | Traversal of DOM

Hey Guys, Hope you loved the last articles on JavaScript DOM, so here it is the 2nd Part: Traversal of DOM. Through Access Specifier, you selected the item, but what if we have to fo through that item through a Tree Structure. It can be:

  1. Parent Node
  2. Child Node
  3. Sibling Node

Root Node:

  1. document: This will give access to the whole document
  2. document.documentElement: This gives access to the HTML part
  3. document.head: Gives access to the head tag.
  4. document.body: Gives access to the body tag.

Parent Node:

  1. parentNode: Will return ... image.png
  1. parentElement.parentElement:

image.png

Children Nodes:

  1. childNodes:
  1. firstChild

image.png

  1. lastChild

image.png

  1. children

image.png

  1. firstElementChild

image.png

  1. lastElementChild

image.png

Siblings Node

  1. previousSibling
  2. nextSibling
  3. previousElementSibling
  4. nextElementSibling

image.png

Thanks for Reading!! hope you learnt something new today.

You can connect with me:

Twitter: twitter.com/heyy_harshh

LinkedIn: linkedin.com/in/harsh-chandwani