if (node.parentElement) {
node.parentElement.style.color = "red";
}Node: parentElement property / notebook
Node: parentElement property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<!doctype html>
<html lang="en-US">
<body>
<script>
const html = document.querySelector("html");
console.log(html.parentElement); // null
console.log(html.parentNode); // document
</script>
</body>
</html>