# How to get the parent of an element in JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Aug 7, 2020, updated Sep 23, 2021. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-dom-get-the-parent-of-an-element

> Learn how to get the parent node of an element by using the parentNode property of the element.

To get the parent node of an HTML element, you can use the `parentNode` property. This property returns the parent node of the specified element as a `Node` object.

Let us say you have the following HTML code:

```html
<div class="wrapper">
    <button id="btn">Click Me</button>
</div>
```

The following example demonstrates how you can get the parent node of `button`:

```javascript
const button = document.querySelector('#btn');

const div = button.parentNode;

console.log(div.classList[0]); // wrapper
```

The `parentNode` property is *read-only*, which means you can not modify it.

> In HTML, the `document` is itself the parent node of `html` element. Both `body` and `head` elements are child nodes of the `html` element.
