DOM

Node.nodeValue プロパティ

 編集:2022.10.28 by T.A.

[Edge]。→

Node の値を取得/設定します。

構文
Node.nodeValue
Node Node

ノードの値を表す¶文字列。

注記

document 自身は、nodeValue は nullを返します。

text ノード、comment ノード、CDATA ノードでは、nodeValue はノードの中身を返します。attribute ノードは属性値を返します。

以下の表は、様々なノードの戻り値を表しています。

¶属性 nodeValue の値
CDATASection CDATA Sectionの中身
コメント commentの中身
Document null
DocumentFragment null
DocumentType null
Element null
NamedNodeMap null
EntityReference null
Notation null
ProcessingInstruction ターゲットを除く全体の内容
Text テキスト ノードの中身

nodeValue が null と定義されている場合、値を設定しても効果はありません。

HTML:

<SPAN id=IdTest><SPAN id=IdSpan>SPAN要素</SPAN><BR id=IdBr>
<INPUT id=IdInput value="INPUT要素"></SPAN>

JavaScript:

NL=IdTest.childNodes;  //IdTest の子ノード リストを得る。
D="";
for(I=0; I<NL.length; I++){  //取得した全てのノードの処理:
  D=D+ NL[I].nodeName +": nodeValue:"+ NL[I].nodeValue +"\\r";  //表示用。
}

表示結果:

SPAN: nodeValue:null
BR: nodeValue:null
#comment: nodeValue:コメント部
#text: nodeValue:

INPUT: nodeValue:null

JavaScript:

IdInput.previousSibling.nodeValue="テストテキスト";

テスト