DOM Interfaces

HTMLSlotElement

Represents a distribution point in a shadow tree, with APIs for inspecting assigned nodes or elements. Slots do not physically move light DOM children into the shadow tree. Fallback content is displayed when nothing is assigned. Example result: 1.

Formal Syntax & Structure

html syntaxhtml
const element = document.getElementById('host').shadowRoot.getElementById('demo'); // HTMLSlotElement

Return Value

HTMLSlotElement

An existing HTML DOM object associated with the slot element in this example; this interface is a type, not a function return contract.

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().length);</script>
HTML Reference