DOM

CharacterData.data プロパティ

 編集:2022.11.10 by T.A.

[Edge]。→

CharacterData のテキスト データの値を表す文字列を返します。

mdn: 現在のオブジェクトのデータの値を表します。

構文
CharacterData.data
CharacterData TextCommentCDATASectionProcessingInstruction

文字列。

data を使用したコメントの読み取り/mdn

以下の例はこの抽象インターフェイスを実装した 2 つの具象インターフェイス、TextComment を使用しています。

HTML:

<!-- This is an HTML comment !-->
<output id="Result"></output>

JavaScript:

let comment = document.body.childNodes[1];
let output = document.getElementById("Result");

output.value = comment.data;

Node.childNodes

HTML:

<SPAN id=IdTest>[SPAN要素。テキスト1<!--[コメント。テキスト2]-->テキスト3<B>[B要素。テキスト4]</B>テキスト5]</SPAN>

JavaScript:

NL=IdTest.childNodes;  //IdTest の子ノード リストを得る。
	//=[object]:[object NodeList]
	//0=[object]:[object Text]
	//1=[object]:[object Comment]
	//2=[object]:[object Text]
	//3=[object]:[object HTMLElement]
	//4=[object]:[object Text]
	//entries=[function]:function entries() { [native code] }
	//…
D=NL[0];  //=[object]:[object Text]
	//wholeText=[string]:[SPAN要素。テキスト1
	//assignedSlot=[object]:null
	//splitText=[function]:function splitText() { [native code] }
	//data=[string]:[SPAN要素。テキスト1
	//length=[number]:13
	//…
D=NL[1];  //=[object]:[object Comment]
	//data=[string]:[コメント。テキスト2]
	//length=[number]:12
	//previousElementSibling=[object]:null
	//…

テスト