HTMLSlotElement: assign() method - Web APIs | MDN
Syntax
js
assign(node1)
assign(node1, node2)
assign(node1, node2, /* …, */ nodeN)
Parameters
Return value
None (undefined).
Exceptions
NotAllowedErrorDOMException-
Thrown when calling this method on an automatically assigned slot.
Examples
In the example below, the assign() method is used to display the correct tab in a tabbed application. The function is called and passed the panel to show, which is then assigned to the slot.
js
function UpdateDisplayTab(elem, tabIdx) {
const shadow = elem.shadowRoot;
const slot = shadow.querySelector("slot");
const panels = elem.querySelectorAll("tab-panel");
if (panels.length && tabIdx && tabIdx <= panels.length) {
slot.assign(panels[tabIdx - 1]);
} else {
slot.assign();
}
}
Specifications
| Specification |
|---|
| HTML # dom-slot-assign |