Web APIs
HTMLSlotElement.prototype.assignedElements()
Returns assigned elements; optional flatten follows flattened slot assignment.
Formal Syntax & Structure
javascript syntaxjavascript
slot.assignedElements([options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| options | object | Optional flatten flag. |
Return Value
Element[]
Returns assigned elements; optional flatten follows flattened slot assignment.
Working Example
Example Snippetjavascript
(async () => {const host=document.createElement("div");const root=host.attachShadow({mode:"open"});root.innerHTML="<slot name=label>fallback</slot>";const span=document.createElement("span");span.slot="label";span.textContent="title";host.append(span);document.body.append(host);const slot=root.querySelector("slot");console.log(slot.assignedElements()[0].textContent,span.parentNode===host);})()