次の関係の説明で正しいものはどれですか。
[ html ]
<div id="parent">
<p id="child"></p>
</div>
- divはpの子ノード
- pはdivの兄弟ノード
- pはdivの親ノード
- pはdivの子ノード
正解
- pはdivの子ノード
解説
<p>要素は<div>の中に含まれるため、pはdivの子ノードです。
使用例(サンプルコード)
[ javascript ]
const parent = document.getElementById("parent");
console.log(parent.firstElementChild.id); // "child"