DOM

Text.assignedSlot プロパティ

 編集:2022.10.31 by T.A.

[Edge]。読取専用。→

mdn: 要素に関連付けられた HTMLSlotElement オブジェクトを返します。

構文
Text.assignedSlot
Text Text

関連付けられている SLOT HTMLSlotElement オブジェクト、該当がない場合は null。

HTML:

<DIV id=IdDiv>
 <SPAN id=IdTest slot=nameSpan>SPAN要素</SPAN>
</DIV>
<TEMPLATE id=IdTemplate>
  <STYLE>
    SLOT{
      color:red;
    }
  </STYLE>
  内容:<SLOT name=nameSpan></SLOT>
</TEMPLATE>

JavaScript:

TempContent=IdTemplate.content.cloneNode(true);  //テンプレートの複製を取得
RE=IdDiv.attachShadow({mode:"open"});  //ホストである IdDiv に Shadow DOM を追加
RE.appendChild(TempContent);  // Shadow DOM に複製テンプレートを追加

D=IdTest.firstChild.assignedSlot;  //テキストに関連付けられている SLOT 要素を得る。
	//=[object]:null
//D=IdTest.assignedSlot;  //要素に関連付けられている SLOT 要素を得る。
	//=[object]:[object HTMLSlotElement]
	//name=[string]:nameSpan
	//

¶テキストに SLOT を関連付けられるのだろうか?。

→要素:SLOTTEMPLATE

contentcloneNode()attachShadow()appendChild()


テスト