Source Code: (back to article)
<!DOCTYPE html>
<html>
<head>
<title>Navigating to Parent Nodes</title>
</head>
<body>
<div id="shopping-cart">
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>

<script>
const cartItem = document.querySelector('li');
const parent = cartItem.parentNode;

// Display the parent node
document.body.insertAdjacentHTML('beforeend', `<h4>The parent of the first cart item is a: ${parent.tagName}</h4>`);
</script>
</body>
</html>