Question 1
Back to Exercise
The page contains this HTML:
<ul id="menu">
<li>Home</li>
<li>Courses</li>
</ul>What does the following JavaScript code print when it runs on this page?
const menu = document.getElementById("menu");
console.log(menu.childNodes.length, menu.children.length);
- A 2 2
- B 3 2
- C 2 5
- D 5 2 Correct
Correct Answer: Option D
The line breaks before, between and after the two li elements are three text nodes: 3 + 2 = 5 childNodes, but only 2 element children.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!