DOM

Node.parentNode プロパティ

 編集:2022.10.29 by T.A.

[Edge]。読取専用。→

Node の親ノードを Node で返します。

mdn: DOM ツリー内の特定のノードの親ノードを返します。

mdn: Document および DocumentFragment ノードには親が付くことはないので、parentNode は常に null になります。ノードが生成されてからツリーに割り当てられていない場合も null を返します。

構文
Node.parentNode
Node Node

NodeElement ノード、Document ノード、または DocumentFragment になります。

HTML:

<SPAN id=IdTest>[SPAN要素。テキスト<B id=IdB>[B要素<I id=IdI>[I要素]</I>]</B>テキスト]</SPAN>

JavaScript:

NL=IdTest.childNodes;  //IdTest の子ノード リストを得る。
	//=[object]:[object NodeList]
	//0=[object]:[object Text]
	//1=[object]:[object HTMLElement]
	//2=[object]:[object Text]
	//entries=[function]:function entries() { [native code] }
	//…
D=NL[0].nodeName;     //=[string]:#text
DA=NL[0].parentNode;  //=[object]:[object HTMLSpanElement]…
D=DA.id;              //=[string]:IdTest

D=NL[1].nodeName;     //=[string]:B
DA=NL[1].parentNode;  //=[object]:[object HTMLSpanElement]…
D=DA.id;              //=[string]:IdTest

DA=IdI.parentNode;  //=[object]:[object HTMLElement]…
D=DA.id;            //=[string]:IdB

D=document.body.parentNode;  //=[object]:[object HTMLHtmlElement]
D=document.parentNode;  //=[object]:null

テスト