This snippet gets the parent of an element by using the
parentNode property of the element.
The following code gets the parent node of the element with the id
const current = document.querySelector('#main'); const parent = current.parentNode;
How it works:
- First, select the element with the CSS selector #main
- Then, use the parentNode property to get the parent element of the selected element.