To directly select a DOM element,
we can use selector methods like
querySelector
or getElementById
. But
sometimes, we need to select an element
based on its relationship with
another element in the DOM tree.
For example, how do we select the
parent of an element?
Take a look at the example given below:
As you can see in the console,
the parentElement
property helps
us in selecting the parent
of an element.