Example 1 — Read assignedSlot (MDN)
Log the named slot a light-DOM child was assigned to.
const slottedSpan = document.querySelector("my-paragraph span");
console.log(slottedSpan.assignedSlot); // <slot name="my-text">
console.log(slottedSpan.assignedSlot.name); // "my-text" How It Works
- Find the child. The
<span>lives in the light DOM of the host. - Read assignedSlot. Because
slot="my-text"matches a named slot, you get anHTMLSlotElement. - Read the name.
assignedSlot.nameis"my-text". - Needs an open shadow. The host must expose an open shadow root for this to work from page script.

