Skip to content

Type Editor


Type Editor / @type-editor/dom-util / parent-node

parent-node

Functions

FunctionDescription

parentNode

Gets the parent node of a DOM node, accounting for Shadow DOM and slot assignments.

This function handles special cases:

  • If the node is slotted, returns the assigned slot
  • If the parent is a DocumentFragment (nodeType 11), returns the shadow root host
  • Otherwise returns the regular parent node

Example

typescript
const element = document.getElementById("myElement");
const parent = parentNode(element);