diff options
Diffstat (limited to 'files/de/web/api/htmlslotelement')
-rw-r--r-- | files/de/web/api/htmlslotelement/assignednodes/index.html | 66 | ||||
-rw-r--r-- | files/de/web/api/htmlslotelement/index.html | 67 |
2 files changed, 133 insertions, 0 deletions
diff --git a/files/de/web/api/htmlslotelement/assignednodes/index.html b/files/de/web/api/htmlslotelement/assignednodes/index.html new file mode 100644 index 0000000000..77ab2aef3d --- /dev/null +++ b/files/de/web/api/htmlslotelement/assignednodes/index.html @@ -0,0 +1,66 @@ +--- +title: HTMLSlotElement.assignedNodes() +slug: Web/API/HTMLSlotElement/assignedNodes +translation_of: Web/API/HTMLSlotElement/assignedNodes +--- +<p>{{APIRef("Shadow DOM API")}}</p> + +<p>Die Eigenschaft <strong><code>assignedNodes()</code></strong> der Schnittstelle {{domxref("HTMLSlotElement")}} gibt die Reihenfolge der diesem Slot zugewiesenen Elemente oder alternativ den Fallback-Inhalt des Slots zurück.</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">var assignedNodes[] = HTMLSlotElement.assignedNodes([options])</pre> + +<h3 id="Parameter">Parameter</h3> + +<dl> + <dt>options {{optional_inline}}</dt> + <dd>Ein Objekt, das Optionen für die zurückzugebenden Knoten festlegt. Die verfügbaren Optionen sind: + <ul> + <li><code>flatten</code>: Ein {{jsxref('Boolean')}}, das angibt, ob die dem Slot zugewiesenen Elemente zurückgegeben werden sollen (wenn dieser Wert <code>false</code> ist) oder der Fallback-Inhalt des Slots (wenn dieser Wert <code>true</code> ist). Die Vorgabe ist <code>false</code>.</li> + </ul> + </dd> +</dl> + +<h3 id="Rückgabewerte">Rückgabewerte</h3> + +<p>Ein Array von Knoten.</p> + +<h2 id="Beispiele">Beispiele</h2> + +<p>Das folgende Schnippsel ist unserem <a href="https://github.com/mdn/web-components-examples/tree/master/slotchange">Slotchange-Beispiel</a> entnommen (<a href="https://mdn.github.io/web-components-examples/slotchange/">siehe auch live</a>).</p> + +<pre class="brush: js">let slots = this.shadowRoot.querySelectorAll('slot'); +slots[1].addEventListener('slotchange', function(e) { + let nodes = slots[1].assignedNodes(); + console.log('Element in Slot "' + slots[1].name + '" changed to "' + nodes[0].outerHTML + '".'); +});</pre> + +<p>Hier nehmen wir Verweise auf alle Slots und fügen dann einen Slotchange Event Listener zum zweiten Slot in der Vorlage hinzu - derjenige, dessen Inhalt im Beispiel geändert wird.</p> + +<p>Jedes Mal, wenn sich das in den Slot eingefügte Element ändert, protokollieren wir einen Bericht an die Konsole, aus dem hervorgeht, welcher Slot sich geändert hat und was der neue Knoten im Slot ist.</p> + +<h2 id="Spezifikationen">Spezifikationen</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG','scripting.html#dom-slot-assignednodes','assignedNodes')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_Kompatibilität">Browser Kompatibilität</h2> + +<div> + + +<p>{{Compat("api.HTMLSlotElement.assignedNodes")}}</p> +</div> diff --git a/files/de/web/api/htmlslotelement/index.html b/files/de/web/api/htmlslotelement/index.html new file mode 100644 index 0000000000..2644171f01 --- /dev/null +++ b/files/de/web/api/htmlslotelement/index.html @@ -0,0 +1,67 @@ +--- +title: HTMLSlotElement +slug: Web/API/HTMLSlotElement +tags: + - API + - HTMLSlotElement + - Interface + - NeedsTranslation + - Reference + - TopicStub + - shadow dom +translation_of: Web/API/HTMLSlotElement +--- +<p>{{APIRef('Web Components')}}</p> + +<p>The <strong><code>HTMLSlotElement</code></strong> interface of the <a href="/en-US/docs/Web/Web_Components/Shadow_DOM">Shadow DOM API</a> enables access to the name and assigned nodes of an HTML {{HTMLElement("slot")}} element.</p> + +<h2 id="Properties">Properties</h2> + +<dl> + <dt>{{domxref('HTMLSlotElement.name')}}</dt> + <dd>{{domxref("DOMString")}}: Can be used to get and set the slot's name.</dd> +</dl> + +<h2 id="Methods">Methods</h2> + +<dl> + <dt>{{domxref('HTMLSlotElement.assignedNodes()')}}</dt> + <dd>Returns the sequence of elements assigned to this slot, or alternatively the slot's fallback content.</dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<p>The following snippet is taken from our <a href="https://github.com/mdn/web-components-examples/tree/master/slotchange">slotchange example</a> (<a href="https://mdn.github.io/web-components-examples/slotchange/">see it live also</a>).</p> + +<pre class="brush: js">let slots = this.shadowRoot.querySelectorAll('slot'); +slots[1].addEventListener('slotchange', function(e) { + let nodes = slots[1].assignedNodes(); + console.log('Element in Slot "' + slots[1].name + '" changed to "' + nodes[0].outerHTML + '".'); +});</pre> + +<p>Here we grab references to all the slots, then add a slotchange event listener to the 2nd slot in the template — which is the one that keeps having its contents changed in the example.</p> + +<p>Every time the element inserted in the slot changes, we log a report to the console saying which slot has changed, and what the new node inside the slot is.</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('HTML WHATWG','scripting.html#htmlslotelement','HTMLSlotElement')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("api.HTMLSlotElement")}}</p> |