DOM Methods
HTMLSlotElement.assignedNodes()
Returns nodes assigned to the slot, including text nodes. If no nodes are assigned, fallback content is returned when applicable. The flatten option resolves nested slot distribution. The result is a snapshot, not a live collection. Example result: 2.
Formal Syntax & Structure
html syntaxhtml
element.assignedNodes(options)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| options | object | Optional flatten Boolean option. |
Return Value
Node[]
Returns nodes assigned to the slot, including text nodes.
Working Example
Example Snippethtml
<div id="host"> Text <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.assignedNodes().length);</script>