DOM Methods
HTMLSlotElement.assignedElements()
Returns elements assigned to the slot, with fallback and flattening behavior defined by the slot algorithm. Text nodes are excluded. Use assignedNodes for text as well; flatten can traverse nested slots and expose fallback elements where appropriate. Example result: Label.
Formal Syntax & Structure
html syntaxhtml
element.assignedElements(options)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| options | object | Optional flatten Boolean option. |
Return Value
Element[]
Returns elements assigned to the slot, with fallback and flattening behavior defined by the slot algorithm.
Working Example
Example Snippethtml
<div id="host"> <span>Label</span></div><script> document.getElementById('host').attachShadow({mode:'open'}).innerHTML='<slot id="demo"></slot>';</script><p> Result: <output id="result"></output></p><script> const e = document.getElementById('host').shadowRoot.getElementById('demo'); const result = value => { document.getElementById("result").textContent = String(value); }; result(e.assignedElements().map(x=>x.textContent).join(','));</script>