document.getElementById(“main”)で返されるのはどの種類のノードですか?
- Textノード
- Attributeノード
- Elementノード
- Commentノード
正解
- Elementノード
解説
getElementByIdは、指定IDを持つ要素を返すため「Elementノード」です。
使用例(サンプルコード)
[ javascript ]
let mainDiv = document.getElementById("main");
console.log(mainDiv.nodeType); // Elementノードは1