dom_dom0100_009

document.getElementById(“main”)で返されるのはどの種類のノードですか?

  1. Textノード
  2. Attributeノード
  3. Elementノード
  4. Commentノード
正解
  1. Elementノード
解説

getElementByIdは、指定IDを持つ要素を返すため「Elementノード」です。

使用例(サンプルコード)

[ javascript ]

let mainDiv = document.getElementById("main");
console.log(mainDiv.nodeType); // Elementノードは1