Question #765   Submitted by Answiki on 10/26/2021 at 07:59:16 PM UTC

How to get parent node of an element in JavaScript?

Answer   Submitted by Answiki on 10/26/2021 at 08:05:55 PM UTC

In JavaScript , the attribute element.parentNode returns the parent node of element. Let's consider the following HTML code:

<div id="daddy">
    <div id="child">
    </div>
</div>

The following JavaScript code returns the parent element of the node child, i.e. the node daddy.

parent = document.getElementById('child').parentNode;

3 events in history
Answer by Answiki on 10/26/2021 at 08:05:55 PM

In JavaScript , the attribute element.parentNode returns the parent node of element. Let's consider the following HTML code:

<div id="daddy">
    <div id="child">
    </div>
</div>

The following JavaScript code returns the parent element of the node child, i.e. the node daddy.

parent = document.getElementById('child').parentNode;

Answer by Answiki on 10/26/2021 at 08:05:18 PM

In JavaScript , the attribute element.parentNode returns the parent node of element. Let's consider the following HTML code:

<div id="parent">
    <div id="child">
    </div>
</div>

The following JavaScript code returns the parent element of the node child.

parent = document.getElementById('child').parentNode;

Question by Answiki 10/26/2021 at 07:59:16 PM
How to get parent node of an element in JavaScript?
# ID Query URL Count

Icons proudly provided by Friconix.